Skip to content

Commit c867b67

Browse files
committed
get home assistant calendar api
1 parent b140cda commit c867b67

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

app/apis/home_assistant_calendar_api.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ def initialize(config = Timeframe::Application.config.local)
33
@config = config
44
end
55

6-
def prepare_response(response)
6+
def fetch
77
start_time = (Time.now - 1.day).utc.iso8601
88
end_time = (Time.now + 5.days).utc.iso8601
99

1010
out = []
1111

12-
response.each do |calendar|
12+
Timeframe::Application.config.local["calendars"].each do |calendar|
13+
next unless calendar["entity_id"].present?
14+
1315
res = HTTParty.get("#{url}/#{calendar["entity_id"]}?start=#{start_time}&end=#{end_time}", headers: headers)
14-
config = Timeframe::Application.config.local["calendars"].find { _1["entity_id"] == calendar["entity_id"] }
1516

1617
res.map! do |event|
1718
event["calendar_entity_id"] = calendar["entity_id"]
@@ -21,10 +22,8 @@ def prepare_response(response)
2122

2223
event["ends_at"] = event["end"]["date"] || event["end"]["dateTime"]
2324

24-
if config
25-
event["icon"] = config["icon"]
26-
event["letter"] = config["letter"]
27-
end
25+
event["icon"] = calendar["icon"]
26+
event["letter"] = calendar["letter"]
2827

2928
event["id"] = event["uid"]
3029

@@ -42,7 +41,11 @@ def prepare_response(response)
4241
out.concat(res)
4342
end
4443

45-
out
44+
save_response(out)
45+
end
46+
47+
def prepare_response(response)
48+
response
4649
end
4750

4851
def headers

config/initializers/sidekiq_cron.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Sidekiq::Cron::Job.create(
1313
name: "Fetch Home Assistant Calendar",
1414
cron: "every 1 minute",
15-
args: ["home_calendar"],
15+
args: ["home_assistant_calendar"],
1616
class: "ScheduleJob"
1717
)
1818

@@ -23,12 +23,12 @@
2323
class: "ScheduleJob"
2424
)
2525

26-
Sidekiq::Cron::Job.create(
27-
name: "Fetch Google Calendar",
28-
cron: "*/1 * * * *",
29-
args: ["google_calendar"],
30-
class: "ScheduleJob"
31-
)
26+
# Sidekiq::Cron::Job.create(
27+
# name: "Fetch Google Calendar",
28+
# cron: "*/1 * * * *",
29+
# args: ["google_calendar"],
30+
# class: "ScheduleJob"
31+
# )
3232

3333
Sidekiq::Cron::Job.create(
3434
name: "Fetch Birdnet",

0 commit comments

Comments
 (0)