Skip to content

Commit

Permalink
Support for delayed start
Browse files Browse the repository at this point in the history
  • Loading branch information
ekutner committed Feb 23, 2022
1 parent be611a3 commit 74497c8
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
4 changes: 2 additions & 2 deletions custom_components/home_connect_alt/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ def program_option_available(self) -> bool:
return self._appliance.connected \
and self._appliance.selected_program \
and self._key in self._appliance.selected_program.options \
and self._appliance.selected_program.key in self._appliance.available_programs \
and not self._appliance.active_program \
and self._appliance.available_programs \
and self._appliance.selected_program.key in self._appliance.available_programs \
and self._appliance.available_programs[self._appliance.selected_program.key].options \
and self._key in self._appliance.available_programs[self._appliance.selected_program.key].options \
and (
"BSH.Common.Status.RemoteControlActive" not in self._appliance.status or
self._appliance.status["BSH.Common.Status.RemoteControlActive"]
self._appliance.status["BSH.Common.Status.RemoteControlActive"].value
)


Expand Down
6 changes: 5 additions & 1 deletion custom_components/home_connect_alt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@
"BSH.Common.Option.FinishInRelative"
],
"status": {
"BSH.Common.Status.DoorState": { "type": "binary_sensor", "class": "door", "on_state": "BSH.Common.EnumType.DoorState.Open" },
"BSH.Common.Status.DoorState": { "type": "binary_sensor", "class": "door", "icon": None, "on_state": "BSH.Common.EnumType.DoorState.Open" },
},
"delayed_start": [
"BSH.Common.Option.FinishInRelative"
],
"options": {
"BSH.Common.Option.FinishInRelative": { "unit": None, "class": f"{DOMAIN}__timespan"},
"BSH.Common.Option.ElapsedProgramTime": { "unit": None, "class": f"{DOMAIN}__timespan"},
"BSH.Common.Option.EstimatedTotalProgramTime": { "unit": None, "class": f"{DOMAIN}__timespan"},
"BSH.Common.Option.RemainingProgramTime": {"class": "timestamp" }
}
}
Expand Down
4 changes: 2 additions & 2 deletions custom_components/home_connect_alt/manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"domain": "home_connect_alt",
"name": "Home Connect Alt",
"version": "0.4.0",
"version": "0.4.1",
"config_flow": true,
"documentation": "https://github.com/ekutner/home-connect-hass",
"issue_tracker": "https://github.com/ekutner/home-connect-hass/issues",
"requirements": ["home-connect-async==0.6.0"],
"requirements": ["home-connect-async==0.6.1"],
"ssdp": [],
"zeroconf": [],
"homekit": {},
Expand Down
60 changes: 59 additions & 1 deletion custom_components/home_connect_alt/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def add_appliance(appliance:Appliance) -> None:
for program in appliance.available_programs.values():
if program.options:
for option in program.options.values():
if option.key not in SPECIAL_ENTITIES['ignore'] and option.allowedvalues and len(option.allowedvalues)>1:
if option.key in SPECIAL_ENTITIES['delayed_start']:
device = DelayedStartSelect(appliance, option.key)
entity_manager.add(device)
elif option.key not in SPECIAL_ENTITIES['ignore'] and option.allowedvalues and len(option.allowedvalues)>1:
device = OptionSelect(appliance, option.key)
entity_manager.add(device)

Expand Down Expand Up @@ -142,6 +145,7 @@ def options(self) -> list[str]:
vals = option.allowedvalues.copy()
vals.append('')
return vals
# return option.allowedvalues
#_LOGGER.info("Allowed values for %s : %s", self._key, None)
return []

Expand All @@ -160,6 +164,9 @@ def current_option(self) -> str:
return None

async def async_select_option(self, option: str) -> None:
if option == '':
_LOGGER.debug('Tried to set an empty option')
return
try:
await self._appliance.async_set_option(self._key, option)
except HomeConnectError as ex:
Expand Down Expand Up @@ -222,3 +229,54 @@ async def async_select_option(self, option: str) -> None:

async def async_on_update(self, appliance:Appliance, key:str, value) -> None:
self.async_write_ha_state()


class DelayedStartSelect(EntityBase, SelectEntity):
""" Class for delayed start select box """
def __init__(self, appliance: Appliance, key: str = None, conf: dict = None) -> None:
super().__init__(appliance, key, conf)
self._current = '0:00'

@property
def icon(self) -> str:
return self._conf.get('icon', 'mdi:clock-outline')

@property
def available(self) -> bool:
available = super().program_option_available
if not available:
self._current = '0:00'
self._appliance.clear_start_option(self._key)
return available

@property
def options(self) -> list[str]:
options = [ "0:00" ]

start = 1
if self._appliance.selected_program and self._appliance.selected_program.options and self._key in self._appliance.selected_program.options:
selected_program_time = self._appliance.selected_program.options[self._key].value
start = int(selected_program_time/1800) + (selected_program_time % 1800 > 0)
#end = self._appliance.available_programs[self._appliance.selected_program.key].options[self._key].max
end = 49
for t in range(start, end):
options.append(f"{int(t/2)}:{(t%2)*30:02}")
return options

@property
def current_option(self) -> str | None:
return self._current

async def async_select_option(self, option: str) -> None:
self._current = option
if option == '0:00':
self._appliance.clear_start_option(self._key)
return
parts = option.split(':')
delay = int(parts[0])*3600 + int(parts[1])*60
self._appliance.set_start_option(self._key, delay)

async def async_on_update(self, appliance:Appliance, key:str, value) -> None:
if key == Events.PROGRAM_FINISHED:
self._current = '0:00'
self.async_write_ha_state()

0 comments on commit 74497c8

Please sign in to comment.