Skip to content

Commit 6a868ea

Browse files
committed
fix: Revert conversion of dates to UTC
- update panel registration (deprecated)
1 parent d7d999d commit 6a868ea

File tree

8 files changed

+37
-38
lines changed

8 files changed

+37
-38
lines changed

custom_components/heatger/frontend/dist/heatger-panel.js

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export const VERSION = '1.0'
1+
export const VERSION = '1.03'
22
export const STOP_FROSTFREE_PAYLOAD = '2023-01-01T00:00'

custom_components/heatger/frontend/src/panel/prog/prog.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { localize } from '../../localize/localize'
88
import { style } from '../../style'
99
import { heatgerGetZones } from '../websocket/ha-ws'
1010
import { heatgerAddProg, heatgerRemoveAllProg, heatgerRemoveProg } from '../api/ha-api'
11-
import { progToUTC } from '../../utils/convert/convert'
1211
import { type ZoneInfo } from '../websocket/dto/zone-info.dto'
1312

1413
@customElement('heatger-prog-card')
@@ -44,13 +43,14 @@ export class HeatgerProgCard extends LitElement {
4443
}
4544
}
4645
const time = form.time.value
46+
console.log(time);
4747
const state = parseInt(form.state.value)
4848
const zone = parseInt(form.zone.value)
4949
if (selectedDays.length === 0 || time === '') return
5050

5151
const progs: Prog[] = []
5252
selectedDays.forEach((day) => {
53-
progs.push(progToUTC({ day, hour: time, state }))
53+
progs.push({ day, hour: time, state })
5454
})
5555
void heatgerAddProg(this.hass, `zone${zone}`, progs).then(() => {
5656
this.updateZonesData()
@@ -59,7 +59,7 @@ export class HeatgerProgCard extends LitElement {
5959

6060
handleDelete (prog: Prog): void {
6161
const zoneNumber = this.currentTab + 1
62-
void heatgerRemoveProg(this.hass, `zone${zoneNumber}`, progToUTC(prog)).then(() => {
62+
void heatgerRemoveProg(this.hass, `zone${zoneNumber}`, prog).then(() => {
6363
this.updateZonesData()
6464
})
6565
}

custom_components/heatger/frontend/src/panel/prog/table_prog.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type CSSResultGroup, html, LitElement, type TemplateResult } from 'lit'
22
import { customElement, property } from 'lit/decorators.js'
33
import { type Prog } from '../api/prog/dto/prog'
4-
import { dayToStr, orderToStr, progFromUTC } from '../../utils/convert/convert';
4+
import { dayToStr, orderToStr } from '../../utils/convert/convert';
55
import { localize } from '../../localize/localize'
66
import { type HomeAssistant } from 'custom-card-helpers'
77
import { style } from '../../style'
@@ -47,7 +47,7 @@ export class HeatgerProgTable extends LitElement {
4747
</thead>
4848
<tbody>
4949
${this.datas.map((value) => {
50-
return this.addRow(progFromUTC(value))
50+
return this.addRow(value)
5151
})}
5252
</tbody>
5353
</table>

custom_components/heatger/panel.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
from homeassistant.components import frontend
22
from homeassistant.components import panel_custom
3+
from homeassistant.components.http import StaticPathConfig
34

45
from custom_components.heatger import DOMAIN
56

67

78
async def async_register_panel(hass):
89
url = F'custom_components/{DOMAIN}/frontend/dist/heatger-panel.js'
910

10-
hass.http.register_static_path(
11-
'/api/panel_custom/heatger',
12-
url,
13-
cache_headers=False
14-
)
11+
await hass.http.async_register_static_paths([
12+
StaticPathConfig('/api/panel_custom/heatger',url, False)
13+
])
1514

1615
await panel_custom.async_register_panel(
1716
hass,

custom_components/heatger/zone/base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Base class"""
22
import abc
3-
from datetime import datetime, time, timedelta
3+
import datetime
44

55
from custom_components.heatger.shared.timer.timer import Timer
66

@@ -21,10 +21,10 @@ def get_remaining_time(self) -> int:
2121
return self.timer.get_remaining_time()
2222

2323
@staticmethod
24-
def get_next_day(weekday: int, hour: time) -> datetime:
24+
def get_next_day(weekday: int, hour: datetime.time) -> datetime:
2525
"""return a datetime"""
26-
now = datetime.utcnow()
27-
actual_weekday = datetime.utcnow().weekday()
26+
now = datetime.datetime.now()
27+
actual_weekday = datetime.datetime.now().weekday()
2828
if actual_weekday > weekday:
2929
next_day = (7 - actual_weekday) + weekday
3030
elif actual_weekday == weekday and \
@@ -33,8 +33,8 @@ def get_next_day(weekday: int, hour: time) -> datetime:
3333
else:
3434
next_day = weekday - actual_weekday
3535

36-
delta = timedelta(days=next_day)
37-
result = datetime.fromtimestamp(datetime.utcnow().timestamp() + delta.total_seconds())
36+
delta = datetime.timedelta(days=next_day)
37+
result = datetime.datetime.fromtimestamp(datetime.datetime.now().timestamp() + delta.total_seconds())
3838
return result.replace(hour=hour.hour, minute=hour.minute, second=0, microsecond=0)
3939

4040
async def stop_loop(self):

custom_components/heatger/zone/zone.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Zone class"""
22
import re
33

4-
from datetime import datetime
4+
import datetime
55
from typing import Optional, Dict
66

77
from homeassistant.core import HomeAssistant
@@ -99,9 +99,10 @@ async def get_next_schedule(self) -> Optional[ScheduleDto]:
9999
if list_schedules is None or len(list_schedules) == 0:
100100
return None
101101

102-
current_schedule = ScheduleDto(datetime.utcnow().weekday(), datetime.utcnow().time(), State.ECO)
102+
current_schedule = ScheduleDto(datetime.datetime.now().weekday(), datetime.datetime.now().time(), State.ECO)
103103
next_schedule: Optional[ScheduleDto] = None
104104
for schedule in list_schedules:
105+
Logs.info("DEBUG", F"current: {current_schedule.to_value()} - next: {schedule.to_value()}")
105106
if current_schedule.to_value() < schedule.to_value():
106107
next_schedule = schedule
107108
break
@@ -113,7 +114,7 @@ async def get_next_schedule(self) -> Optional[ScheduleDto]:
113114
def get_remaining_time_from_schedule(schedule: ScheduleDto) -> int:
114115
"""Return the remaining time between the next schedule and now"""
115116
schedule_date = Zone.get_next_day(schedule.day, schedule.hour)
116-
return int(schedule_date.timestamp() - datetime.utcnow().timestamp())
117+
return int(schedule_date.timestamp() - datetime.datetime.now().timestamp())
117118

118119
async def launch_ping(self) -> None:
119120
"""Start users presence check"""

custom_components/heatger/zone/zone_manager.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Zone manager class"""
2-
from datetime import datetime
2+
import datetime
33
from typing import Optional
44
import voluptuous as vol
55

@@ -42,7 +42,6 @@ async def init_zones(self) -> None:
4242
await self.init_zones_from_config_file()
4343
except KeyError:
4444
Logs.info('INIT', len(self.zones))
45-
pass
4645

4746
async def init_zones_from_config_file(self) -> None:
4847
"""Initialize zones from config file"""
@@ -96,11 +95,11 @@ async def toggle_frost_free(self, end_date: str = None) -> None:
9695
Logs.error(CLASSNAME, F'{State.FROSTFREE} - empty data')
9796
return
9897
try:
99-
end_date = datetime.strptime(end_date, '%Y-%m-%dT%H:%M:%S.%fZ')
98+
end_date = datetime.datetime.strptime(end_date, '%Y-%m-%dT%H:%M:%S.%fZ')
10099
except ValueError:
101100
Logs.error(CLASSNAME, F'{State.FROSTFREE} - invalid date format')
102101
return
103-
if end_date > datetime.now():
102+
if end_date > datetime.datetime.now():
104103
await self.frostfree.start(end_date)
105104
else:
106105
await self.frostfree.stop()

0 commit comments

Comments
 (0)