Skip to content

Commit

Permalink
Fixes to 0.6.0-b1
Browse files Browse the repository at this point in the history
Proper handling of config when entity_settings are not specified
Fixes for delayed operation
Fixes #159
  • Loading branch information
ekutner committed Feb 6, 2023
1 parent 42bbdff commit 2bacec1
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 28 deletions.
14 changes: 7 additions & 7 deletions .devcontainer/config/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ tts:
logger:
default: info
logs:
home_connect_async: error
home_connect_alt: error
home_connect_async: debug
home_connect_alt: debug
custom_components.home_connect_alt: error
homeassistant.helpers.config_entry_oauth2_flow: debug

Expand All @@ -36,9 +36,9 @@ home_connect_alt:
language: en
sensor_value_translation: local
name_template: $appliance $name ($brand)
log_mode: 5
log_mode: 7
#api_host: https://simulator.home-connect.com
entity_settings:
LaundryCare.Washer.Setting.IDos2BaseLevel:
unit: xx
icon: mdi:waves-arrow-up
# entity_settings:
# LaundryCare.Washer.Setting.IDos2BaseLevel:
# unit: xx
# icon: mdi:waves-arrow-up
2 changes: 1 addition & 1 deletion custom_components/home_connect_alt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
vol.Optional(CONF_SENSORS_TRANSLATION, default=None): vol.Any(str, None),
vol.Optional(CONF_NAME_TEMPLATE, default=None): vol.Any(str, None),
vol.Optional(CONF_LOG_MODE, default=None): vol.Any(int, None),
vol.Optional(CONF_ENTITY_SETTINGS, default=None): vol.Any(dict, None)
vol.Optional(CONF_ENTITY_SETTINGS, default={}): vol.Any(dict, None)
}
)
},
Expand Down
6 changes: 3 additions & 3 deletions custom_components/home_connect_alt/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.update(ENTITY_SETTINGS)
if Configuration._global_config:
self.update(self.__merge(self,Configuration._global_config))
self.update(self.__merge(self, Configuration._global_config))

def __merge(self, destination:dict, source:dict ):
for key, value in source.items():
Expand All @@ -212,13 +212,13 @@ def __merge(self, destination:dict, source:dict ):

def get_entity_setting(self, key:str, option:str, default=None):
""" Retrun an entity config setting or None if it doesn't exist """
if CONF_ENTITY_SETTINGS in self and key in self[CONF_ENTITY_SETTINGS] and option in self[CONF_ENTITY_SETTINGS][key]:
if CONF_ENTITY_SETTINGS in self and self[CONF_ENTITY_SETTINGS] and key in self[CONF_ENTITY_SETTINGS] and option in self[CONF_ENTITY_SETTINGS][key]:
return self[CONF_ENTITY_SETTINGS][key][option]
return default

def has_entity_setting(self, key:str, option:str) -> bool:
"""Checks if the entity config setting exist """
if CONF_ENTITY_SETTINGS in self and key in self[CONF_ENTITY_SETTINGS] and option in self[CONF_ENTITY_SETTINGS][key]:
if CONF_ENTITY_SETTINGS in self and self[CONF_ENTITY_SETTINGS] and key in self[CONF_ENTITY_SETTINGS] and option in self[CONF_ENTITY_SETTINGS][key]:
return True
return False

Expand Down
2 changes: 1 addition & 1 deletion custom_components/home_connect_alt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

ENTITY_SETTINGS = {
CONF_ENTITY_SETTINGS: {
"BSH.Common.Option.FinishInRelative": { "unit": None, "class": f"{DOMAIN}__timespan", "delayed_start": True},
"BSH.Common.Option.FinishInRelative": { "type": "DelayedOperation", "unit": None, "class": f"{DOMAIN}__timespan", "delayed_start": True},
"BSH.Common.Option.ElapsedProgramTime": { "unit": None, "class": f"{DOMAIN}__timespan"},
"BSH.Common.Option.EstimatedTotalProgramTime": { "unit": None, "class": f"{DOMAIN}__timespan"},
"BSH.Common.Option.RemainingProgramTime": {"unit": None, "class": "timestamp" },
Expand Down
5 changes: 3 additions & 2 deletions custom_components/home_connect_alt/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ async def async_setup_entry(hass:HomeAssistant , config_entry:ConfigType, async_
entity_manager = EntityManager(async_add_entities)

conf = Configuration()
number_types = ["Int", "Float", "Double"]
def add_appliance(appliance:Appliance) -> None:
if appliance.available_programs:
for program in appliance.available_programs.values():
if program.options:
for option in program.options.values():
if not conf.get_entity_setting(option.key, "ignore") and option.type in ["Int", "Float", "Double"]:
if (not conf.has_entity_setting(option.key, "type") and option.type in number_types) or conf.has_entity_setting(option.key, "type") in number_types:
device = OptionNumber(appliance, option.key, hc_obj=option)
entity_manager.add(device)

if appliance.settings:
for setting in appliance.settings.values():
if not conf.get_entity_setting(setting.key, "ignore") and setting.type in ["Int", "Float", "Double"]:
if (not conf.has_entity_setting(setting.key, "type") and setting.type in number_types) or conf.has_entity_setting(setting.key, "type") in number_types:
device = SettingsNumber(appliance, setting.key, hc_obj=setting)
entity_manager.add(device)

Expand Down
19 changes: 12 additions & 7 deletions custom_components/home_connect_alt/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ def add_appliance(appliance:Appliance) -> None:
for program in appliance.available_programs.values():
if program.options:
for option in program.options.values():
if conf.get_entity_setting(option.key, "delayed_start"):
device = DelayedStartSelect(appliance, option.key, conf)
if conf.get_entity_setting(option.key, "type") == "DelayedOperation":
device = DelayedOperationSelect(appliance, option.key, conf, option)
entity_manager.add(device)
elif not conf.get_entity_setting(option.key, "ignore") and option.allowedvalues and len(option.allowedvalues)>1:
elif option.allowedvalues and len(option.allowedvalues)>1:
device = OptionSelect(appliance, option.key, conf)
entity_manager.add(device)

if appliance.settings:
for setting in appliance.settings.values():
if not conf.get_entity_setting(setting.key, "ignore") and setting.allowedvalues and len(setting.allowedvalues)>1 and not is_boolean_enum(setting.allowedvalues):
if setting.allowedvalues and len(setting.allowedvalues)>1 and not is_boolean_enum(setting.allowedvalues):
device = SettingsSelect(appliance, setting.key, conf)
entity_manager.add(device)

Expand Down Expand Up @@ -240,16 +240,21 @@ async def async_on_update(self, appliance:Appliance, key:str, value) -> None:
self.async_write_ha_state()


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

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

@property
def name_ext(self) -> str|None:
""" Provide the suffix of the name, can be be overriden by sub-classes to provide a custom or translated display name """
return self._hc_obj.name if self._hc_obj.name else "Delayed operation"

@property
def available(self) -> bool:
available = super().program_option_available
Expand Down
9 changes: 5 additions & 4 deletions custom_components/home_connect_alt/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ def add_appliance(appliance:Appliance) -> None:
for program in appliance.available_programs.values():
if program.options:
for option in program.options.values():
if not conf.get_entity_setting(option.key, "ignore") \
and (option.type == "Boolean" or isinstance(option.value, bool) or conf.get_entity_setting(option.key, "type") == "Boolean" ):
if ( not conf.has_entity_setting(option.key, "type") and (option.type == "Boolean" or isinstance(option.value, bool))) \
or conf.get_entity_setting(option.key, "type") == "Boolean" :
device = OptionSwitch(appliance, option.key, conf)
entity_manager.add(device)

if appliance.settings:
for setting in appliance.settings.values():
if not conf.get_entity_setting(setting.key, "ignore") \
and ( setting.type == "Boolean" or isinstance(setting.value, bool) or is_boolean_enum(setting.allowedvalues) or conf.get_entity_setting(setting.key, "type") == "Boolean" ):
if (not conf.has_entity_setting(setting.key, "type")
and ( setting.type == "Boolean" or isinstance(setting.value, bool) or is_boolean_enum(setting.allowedvalues))) \
or conf.get_entity_setting(setting.key, "type") == "Boolean":
device = SettingsSwitch(appliance, setting.key, conf)
entity_manager.add(device)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
"home_connect_alt__options": {
"BSH.Common.Option.Duration": "Duration",
"BSH.Common.Option.ElapsedProgramTime": "Elapsed Program Time",
"BSH.Common.Option.FinishInRelative": "Finish In Relative",
"BSH.Common.Option.FinishInRelative": "Finish In (Delayed Operation)",
"BSH.Common.Option.ProgramProgress": "Program Progress",
"BSH.Common.Option.RemainingProgramTime": "Remaining Program Time",
"BSH.Common.Option.StartInRelative": "Start In Relative",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
"home_connect_alt__options": {
"BSH.Common.Option.Duration": "מֶשֶׁך",
"BSH.Common.Option.ElapsedProgramTime": "זמן תוכנית שחלף",
"BSH.Common.Option.FinishInRelative": "סיים באופן יחסי",
"BSH.Common.Option.FinishInRelative": "סיום בעוד (הפעלה דחויה)",
"BSH.Common.Option.ProgramProgress": "התקדמות התוכנית",
"BSH.Common.Option.RemainingProgramTime": "זמן התוכנית שנותר",
"BSH.Common.Option.StartInRelative": "התחל באופן יחסי",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"home_connect_alt__options": {
"BSH.Common.Option.Duration": "מֶשֶׁך",
"BSH.Common.Option.ElapsedProgramTime": "זמן תוכנית שחלף",
"BSH.Common.Option.FinishInRelative": "סיים באופן יחסי",
"BSH.Common.Option.FinishInRelative": "סיום בעוד (הפעלה דחויה)",
"BSH.Common.Option.ProgramProgress": "התקדמות התוכנית",
"BSH.Common.Option.RemainingProgramTime": "זמן התוכנית שנותר",
"BSH.Common.Option.StartInRelative": "התחל באופן יחסי",
Expand Down

0 comments on commit 2bacec1

Please sign in to comment.