Skip to content

Commit

Permalink
Replaced AwayForDays with AwayForHours
Browse files Browse the repository at this point in the history
  • Loading branch information
dbuezas committed Feb 27, 2023
1 parent 253ea7b commit bda1fe0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
18 changes: 9 additions & 9 deletions custom_components/dbuezas_eq3btsmart/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def async_setup_entry(
OffsetTemperature(eq3),
WindowOpenTemperature(eq3),
WindowOpenTimeout(eq3),
AwayForDays(eq3),
AwayForHours(eq3),
AwayTemperature(eq3),
]
async_add_entities(new_devices)
Expand Down Expand Up @@ -162,16 +162,16 @@ async def async_set_native_value(self, value: float) -> None:
)


class AwayForDays(RestoreNumber):
class AwayForHours(RestoreNumber):
def __init__(self, _thermostat: Thermostat):
self._thermostat = _thermostat
self._attr_has_entity_name = True
self._attr_mode = NumberMode.BOX
self._attr_name = "Away Days"
self._attr_native_min_value = 0
self._attr_native_max_value = 365
self._attr_name = "Away Hours"
self._attr_native_min_value = 0.5
self._attr_native_max_value = 1000000
self._attr_native_step = 0.5
self._attr_native_unit_of_measurement = "days"
self._attr_native_unit_of_measurement = "hours"

@property
def unique_id(self) -> str:
Expand All @@ -189,14 +189,14 @@ async def async_added_to_hass(self) -> None:

data = await self.async_get_last_number_data()
if data and data.native_value != None:
self._thermostat.default_away_days = data.native_value
self._thermostat.default_away_hours = data.native_value

async def async_set_native_value(self, value: float) -> None:
self._thermostat.default_away_days = value
self._thermostat.default_away_hours = value

@property
def native_value(self) -> float | None:
return self._thermostat.default_away_days
return self._thermostat.default_away_hours


class AwayTemperature(Base, RestoreNumber):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(
self._presets = None
self._device_data = None
self._schedule = {}
self.default_away_days: float = 30
self.default_away_hours: float = 30 * 24
self.default_away_temp: float = 12

from .bleakconnection import BleakConnection
Expand Down Expand Up @@ -275,7 +275,12 @@ async def async_set_away(self, away: bool):
_LOGGER.debug("[%s] Disabling away, going to auto mode.", self.name)
return await self._async_set_mode(0x00)

away_end = datetime.now() + timedelta(days=self.default_away_days)
away_end = datetime.now() + timedelta(hours=self.default_away_hours)

# rounding
away_end = away_end + timedelta(minutes=15)
away_end = away_end - timedelta(minutes=away_end.minute % 30)

temperature = self.default_away_temp
_LOGGER.debug(
"[%s] Setting away until %s, temp %s", self.name, away_end, temperature
Expand Down

0 comments on commit bda1fe0

Please sign in to comment.