From b95c08e58ee03686017aaf000537d74bcd9ee5c8 Mon Sep 17 00:00:00 2001 From: "mike.toggweiler" Date: Fri, 15 Nov 2024 13:23:42 +0100 Subject: [PATCH] added switches of configuration block --- custom_components/askoheat/api.py | 190 +--------- custom_components/askoheat/api_conf_desc.py | 367 ++++++++++++++++++++ custom_components/askoheat/const.py | 6 +- custom_components/askoheat/model.py | 4 +- custom_components/askoheat/switch.py | 8 + 5 files changed, 388 insertions(+), 187 deletions(-) diff --git a/custom_components/askoheat/api.py b/custom_components/askoheat/api.py index 8ec7976..c5b815a 100644 --- a/custom_components/askoheat/api.py +++ b/custom_components/askoheat/api.py @@ -249,189 +249,8 @@ def __map_config_data(self, data: ModbusPDU) -> AskoheatDataBlock: """Map modbus result of config data block.""" return AskoheatDataBlock( number_inputs={}, - switches={ - # TODO: Move/merge to api_conf_desc.py - # input settings register - # low byte - SwitchAttrKey.CON_MISSING_CURRENT_FLOW_TRIGGERS_ERROR: _read_flag( - data.registers[2], 0 - ), - SwitchAttrKey.CON_HEATER_LOAD_VALUE_ONLY_IF_CURRENT_FLOWS: _read_flag( - data.registers[2], 1 - ), - SwitchAttrKey.CON_LOAD_FEEDIN_VALUE_ENABLED: _read_flag( - data.registers[2], 2 - ), - SwitchAttrKey.CON_LOAD_SETPOINT_VALUE_ENABLED: _read_flag( - data.registers[2], 3 - ), - SwitchAttrKey.CON_SET_HEATER_STEP_VALUE_ENABLED: _read_flag( - data.registers[2], 4 - ), - SwitchAttrKey.CON_SET_ANALOG_INPUT_ENABLED: _read_flag( - data.registers[2], 5 - ), - SwitchAttrKey.CON_HEATPUMP_REQUEST_INPUT_ENABLED: _read_flag( - data.registers[2], 6 - ), - SwitchAttrKey.CON_EMERGENCY_MODE_ENABLED: _read_flag( - data.registers[2], 7 - ), - # high byte - SwitchAttrKey.CON_HOLD_MINIMAL_TEMPERATURE_ENABELD: _read_flag( - data.registers[2], 8 - ), - SwitchAttrKey.CON_HOLD_MINIMAL_TEMPERATURE_ENABELD: _read_flag( - data.registers[2], 9 - ), - SwitchAttrKey.CON_SOFTWARE_CONTROL_SMA_SEMP_ENABLED: _read_flag( - data.registers[2], 10 - ), - SwitchAttrKey.CON_SOFTWARE_CONTROL_SENEC_HOME_ENABLED: _read_flag( - data.registers[2], 11 - ), - # auto heater off settings register - # low byte - SwitchAttrKey.CON_AUTO_OFF_ENABLED: _read_flag(data.registers[4], 0), - SwitchAttrKey.CON_RESTART_IF_ENERGYMANAGER_CONNECTION_LOST: _read_flag( - data.registers[4], 1 - ), - SwitchAttrKey.CON_AUTO_OFF_MODBUS_ENABLED: _read_flag( - data.registers[4], 4 - ), - SwitchAttrKey.CON_AUTO_OFF_ANALOG_INPUT_ENABLED: _read_flag( - data.registers[4], 5 - ), - SwitchAttrKey.CON_AUTO_OFF_HEAT_PUMP_REQUEST_ENABLED: _read_flag( - data.registers[4], 6 - ), - SwitchAttrKey.CON_AUTO_OFF_EMERGENCY_MODE_ENABLED: _read_flag( - data.registers[4], 7 - ), - # heatbuffer type register - SwitchAttrKey.CON_HEATBUFFER_TYPE_TAP_WATER: _read_flag( - data.registers[6], 0 - ), - SwitchAttrKey.CON_HEATBUFFER_TYPE_HEATING_WATER: _read_flag( - data.registers[6], 1 - ), - SwitchAttrKey.CON_HEATBUFFER_TYPE_COMBINED_HEAT_AND_POWER_UNIT: _read_flag( - data.registers[6], 2 - ), - SwitchAttrKey.CON_HEATBUFFER_TYPE_PELLET_FIRING: _read_flag( - data.registers[6], 3 - ), - SwitchAttrKey.CON_HEATBUFFER_TYPE_GAS_BURNER: _read_flag( - data.registers[6], 4 - ), - SwitchAttrKey.CON_HEATBUFFER_TYPE_OIL_BURNER: _read_flag( - data.registers[6], 5 - ), - SwitchAttrKey.CON_HEATBUFFER_TYPE_HEAT_PUMP: _read_flag( - data.registers[6], 6 - ), - SwitchAttrKey.CON_HEATBUFFER_TYPE_OTHER: _read_flag( - data.registers[6], 7 - ), - # heater position register - SwitchAttrKey.CON_HEATER_POSITION_BOTTOM: _read_flag( - data.registers[8], 0 - ), - SwitchAttrKey.CON_HEATER_POSITION_MIDDLE: _read_flag( - data.registers[8], 1 - ), - SwitchAttrKey.CON_HEATER_POSITION_ASKOWALL: _read_flag( - data.registers[8], 7 - ), - # legio settings register - # low byte - SwitchAttrKey.CON_LEGIO_SETTINGS_USE_INTERNAL_TEMP_SENSOR: _read_flag( - data.registers[9], 0 - ), - SwitchAttrKey.CON_LEGIO_SETTINGS_USE_EXTERNAL_TEMP_SENSOR1: _read_flag( - data.registers[9], 1 - ), - SwitchAttrKey.CON_LEGIO_SETTINGS_USE_EXTERNAL_TEMP_SENSOR2: _read_flag( - data.registers[9], 2 - ), - SwitchAttrKey.CON_LEGIO_SETTINGS_USE_EXTERNAL_TEMP_SENSOR3: _read_flag( - data.registers[9], 3 - ), - SwitchAttrKey.CON_LEGIO_SETTINGS_USE_EXTERNAL_TEMP_SENSOR4: _read_flag( - data.registers[9], 4 - ), - # high byte - SwitchAttrKey.CON_LEGIO_SETTINGS_INTERVAL_DAILY: _read_flag( - data.registers[9], 8 - ), - SwitchAttrKey.CON_LEGIO_SETTINGS_INTERVAL_WEEKLY: _read_flag( - data.registers[9], 9 - ), - SwitchAttrKey.CON_LEGIO_SETTINGS_INTERVAL_FORTNIGHTLY: _read_flag( - data.registers[9], 10 - ), - SwitchAttrKey.CON_LEGIO_SETTINGS_INTERVAL_MONTHLY: _read_flag( - data.registers[9], 11 - ), - SwitchAttrKey.CON_LEGIO_SETTINGS_PREFER_FEEDIN_ENERGY: _read_flag( - data.registers[9], 12 - ), - SwitchAttrKey.CON_LEGIO_SETTINGS_PROTECTION_ENABLED: _read_flag( - data.registers[9], 13 - ), - # house type settings register - # low byte - SwitchAttrKey.CON_HOUSE_TYPE_SINGLE_FAMILY_HOUSE: _read_flag( - data.registers[20], 0 - ), - SwitchAttrKey.CON_HOUSE_TYPE_TWO_FAMILY_HOUSE: _read_flag( - data.registers[20], 1 - ), - SwitchAttrKey.CON_HOUSE_TYPE_APPARTMENT_BUILDING: _read_flag( - data.registers[20], 2 - ), - SwitchAttrKey.CON_HOUSE_TYPE_COMMERCIAL_BUILDING: _read_flag( - data.registers[20], 7 - ), - # Summer time int 1/0 as bool - SwitchAttrKey.CON_SUMMERTIME_ENABLED: _read_int16(data.registers[42]) - == 1, - # rtu settings register - # low byte - SwitchAttrKey.CON_RTU_SEND_TWO_STOP_BITS: _read_flag( - data.registers[49], 0 - ), - SwitchAttrKey.CON_RTU_SEND_PARITY_EVEN: _read_flag( - data.registers[49], 1 - ), - SwitchAttrKey.CON_RTU_SEND_PARITY_ODD: _read_flag( - data.registers[49], 2 - ), - SwitchAttrKey.CON_RTU_SLAVE_MODE_ACTIVE: _read_flag( - data.registers[49], 7 - ), - # high byte - SwitchAttrKey.CON_RTU_MASTER_MODE_ACTIVE: _read_flag( - data.registers[49], 15 - ), - # temperature settings register - # low byte - SwitchAttrKey.CON_USE_INTERNAL_TEMP_SENSOR: _read_flag( - data.registers[94], 0 - ), - SwitchAttrKey.CON_USE_EXTERNAL_TEMP_SENSOR1: _read_flag( - data.registers[94], 1 - ), - SwitchAttrKey.CON_USE_EXTERNAL_TEMP_SENSOR2: _read_flag( - data.registers[94], 2 - ), - SwitchAttrKey.CON_USE_EXTERNAL_TEMP_SENSOR3: _read_flag( - data.registers[94], 3 - ), - SwitchAttrKey.CON_USE_EXTERNAL_TEMP_SENSOR4: _read_flag( - data.registers[94], 4 - ), - }, + switches={}, + # TODO: Move/merge to api_conf_desc.py time_inputs={ TimeAttrKey.CON_LEGIO_PROTECTION_PREFERRED_START_TIME: _read_time( register_value_hours=data.registers[12], @@ -446,9 +265,11 @@ def __map_config_data(self, data: ModbusPDU) -> AskoheatDataBlock: minute=_read_byte(data.registers[55]), ), }, + # TODO: Move/merge to api_conf_desc.py text_inputs={ TextAttrKey.CON_INFO_STRING: _read_str(data.registers[22:38]), }, + # TODO: Move/merge to api_conf_desc.py select_inputs={ SelectAttrKey.CON_RTU_BAUDRATE: _read_enum( data.registers[46:49], Baurate @@ -522,6 +343,9 @@ def _read_register_boolean_input( if isinstance(result, bool): return result + if isinstance(result, number): + return result == 1 + LOGGER.error( "Cannot read bool input from descriptor %r, unsupported value %r", desc, diff --git a/custom_components/askoheat/api_conf_desc.py b/custom_components/askoheat/api_conf_desc.py index 7046dac..37a3236 100644 --- a/custom_components/askoheat/api_conf_desc.py +++ b/custom_components/askoheat/api_conf_desc.py @@ -15,6 +15,7 @@ from custom_components.askoheat.api_desc import ( ByteRegisterInputDescriptor, + FlagRegisterInputDescriptor, Float32RegisterInputDescriptor, RegisterBlockDescriptor, SignedIntRegisterInputDescriptor, @@ -22,9 +23,11 @@ ) from custom_components.askoheat.const import ( NumberAttrKey, + SwitchAttrKey, ) from custom_components.askoheat.model import ( AskoheatNumberEntityDescription, + AskoheatSwitchEntityDescription, ) CONF_REGISTER_BLOCK_DESCRIPTOR = RegisterBlockDescriptor( @@ -489,4 +492,368 @@ api_descriptor=ByteRegisterInputDescriptor(99), ), ], + switches=[ + ### input settings register - begin + # low byte + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_MISSING_CURRENT_FLOW_TRIGGERS_ERROR, + entity_category=EntityCategory.CONFIG, + icon="mdi:alert-circle", + api_descriptor=FlagRegisterInputDescriptor(2, 0), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_HEATER_LOAD_VALUE_ONLY_IF_CURRENT_FLOWS, + entity_category=EntityCategory.CONFIG, + icon="mdi:home-lightning-bolt", + api_descriptor=FlagRegisterInputDescriptor(2, 1), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_LOAD_FEEDIN_VALUE_ENABLED, + entity_category=EntityCategory.CONFIG, + icon="mdi:solar-power", + api_descriptor=FlagRegisterInputDescriptor(2, 2), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_LOAD_SETPOINT_VALUE_ENABLED, + entity_category=EntityCategory.CONFIG, + icon="mdi:stairs", + api_descriptor=FlagRegisterInputDescriptor(2, 3), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_SET_HEATER_STEP_VALUE_ENABLED, + entity_category=EntityCategory.CONFIG, + icon="mdi:gauge", + api_descriptor=FlagRegisterInputDescriptor(2, 4), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_SET_ANALOG_INPUT_ENABLED, + entity_category=EntityCategory.CONFIG, + icon="mdi:since-wave", + api_descriptor=FlagRegisterInputDescriptor(2, 5), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_HEATPUMP_REQUEST_INPUT_ENABLED, + entity_category=EntityCategory.CONFIG, + icon="mdi:heat-pump", + api_descriptor=FlagRegisterInputDescriptor(2, 6), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_EMERGENCY_MODE_ENABLED, + entity_category=EntityCategory.CONFIG, + icon="mdi:car-emergency", + api_descriptor=FlagRegisterInputDescriptor(2, 7), + ), + # high byte + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_LOW_TARIFF_OPTION_ENABLED, + entity_category=EntityCategory.CONFIG, + icon="mdi:weather-night", + api_descriptor=FlagRegisterInputDescriptor(2, 8), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_HOLD_MINIMAL_TEMPERATURE_ENABLED, + entity_category=EntityCategory.CONFIG, + icon="mdi:thermometer-check", + api_descriptor=FlagRegisterInputDescriptor(2, 9), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_SOFTWARE_CONTROL_SMA_SEMP_ENABLED, + entity_category=EntityCategory.CONFIG, + icon="mdi:car-cruise-control", + api_descriptor=FlagRegisterInputDescriptor(2, 10), + entity_registry_enabled_default=False, + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_SOFTWARE_CONTROL_SENEC_HOME_ENABLED, + entity_category=EntityCategory.CONFIG, + icon="mdi:car-cruise-control", + api_descriptor=FlagRegisterInputDescriptor(2, 11), + entity_registry_enabled_default=False, + ), + ### input settings register - end + ### auto heater off settings register - begin + # low byte + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_AUTO_OFF_MODBUS_TIMEOUT_ENABLED, + entity_category=EntityCategory.CONFIG, + icon="mdi:timer-cancel", + api_descriptor=FlagRegisterInputDescriptor(4, 0), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_RESTART_IF_ENERGYMANAGER_CONNECTION_LOST, + entity_category=EntityCategory.CONFIG, + icon="mdi:timer-cancel", + api_descriptor=FlagRegisterInputDescriptor(4, 1), + ), + # bit 2 not used + # bit 3 not used + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_AUTO_OFF_MODBUS_ENABLED, + entity_category=EntityCategory.CONFIG, + icon="mdi:timer-cancel", + api_descriptor=FlagRegisterInputDescriptor(4, 4), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_AUTO_OFF_ANALOG_INPUT_ENABLED, + entity_category=EntityCategory.CONFIG, + icon="mdi:timer-cancel", + api_descriptor=FlagRegisterInputDescriptor(4, 5), + entity_registry_enabled_default=False, + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_AUTO_OFF_HEAT_PUMP_REQUEST_ENABLED, + entity_category=EntityCategory.CONFIG, + icon="mdi:timer-cancel", + api_descriptor=FlagRegisterInputDescriptor(4, 6), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_AUTO_OFF_EMERGENCY_MODE_ENABLED, + entity_category=EntityCategory.CONFIG, + icon="mdi:timer-cancel", + api_descriptor=FlagRegisterInputDescriptor(4, 7), + ), + ### auto heater off settings register - end + ### heatbuffer type register - begin + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_HEATBUFFER_TYPE_TAP_WATER, + entity_category=EntityCategory.CONFIG, + icon="mdi:water-boiler", + api_descriptor=FlagRegisterInputDescriptor(6, 0), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_HEATBUFFER_TYPE_HEATING_WATER, + entity_category=EntityCategory.CONFIG, + icon="mdi:water-boiler", + api_descriptor=FlagRegisterInputDescriptor(6, 1), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_HEATBUFFER_TYPE_COMBINED_HEAT_AND_POWER_UNIT, + entity_category=EntityCategory.CONFIG, + icon="mdi:water-boiler", + api_descriptor=FlagRegisterInputDescriptor(6, 2), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_HEATBUFFER_TYPE_PELLET_FIRING, + entity_category=EntityCategory.CONFIG, + icon="mdi:water-boiler", + api_descriptor=FlagRegisterInputDescriptor(6, 3), + entity_registry_enabled_default=False, + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_HEATBUFFER_TYPE_GAS_BURNER, + entity_category=EntityCategory.CONFIG, + icon="mdi:water-boiler", + api_descriptor=FlagRegisterInputDescriptor(6, 4), + entity_registry_enabled_default=False, + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_HEATBUFFER_TYPE_OIL_BURNER, + entity_category=EntityCategory.CONFIG, + icon="mdi:water-boiler", + api_descriptor=FlagRegisterInputDescriptor(6, 5), + entity_registry_enabled_default=False, + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_HEATBUFFER_TYPE_HEAT_PUMP, + entity_category=EntityCategory.CONFIG, + icon="mdi:water-boiler", + api_descriptor=FlagRegisterInputDescriptor(6, 6), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_HEATBUFFER_TYPE_OTHER, + entity_category=EntityCategory.CONFIG, + icon="mdi:water-boiler", + api_descriptor=FlagRegisterInputDescriptor(6, 7), + ), + ### heatbuffer type register - end + ### heater position register - begin + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_HEATER_POSITION_BOTTOM, + entity_category=EntityCategory.CONFIG, + icon="mdi:format-vertical-align-bottom", + api_descriptor=FlagRegisterInputDescriptor(8, 0), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_HEATER_POSITION_MIDDLE, + entity_category=EntityCategory.CONFIG, + icon="mdi:format-vertical-align-center", + api_descriptor=FlagRegisterInputDescriptor(8, 1), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_HEATER_POSITION_ASKOWALL, + entity_category=EntityCategory.CONFIG, + icon="mdi:wall", + api_descriptor=FlagRegisterInputDescriptor(8, 7), + ), + ### heater position register - end + ### legio settings register - begin + # low byte + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_LEGIO_SETTINGS_USE_INTERNAL_TEMP_SENSOR, + entity_category=EntityCategory.CONFIG, + icon="mdi:water-thermometer", + api_descriptor=FlagRegisterInputDescriptor(9, 0), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_LEGIO_SETTINGS_USE_EXTERNAL_TEMP_SENSOR1, + entity_category=EntityCategory.CONFIG, + icon="mdi:water-thermometer", + api_descriptor=FlagRegisterInputDescriptor(9, 1), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_LEGIO_SETTINGS_USE_EXTERNAL_TEMP_SENSOR2, + entity_category=EntityCategory.CONFIG, + icon="mdi:water-thermometer", + api_descriptor=FlagRegisterInputDescriptor(9, 2), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_LEGIO_SETTINGS_USE_EXTERNAL_TEMP_SENSOR3, + entity_category=EntityCategory.CONFIG, + icon="mdi:water-thermometer", + api_descriptor=FlagRegisterInputDescriptor(9, 3), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_LEGIO_SETTINGS_USE_EXTERNAL_TEMP_SENSOR4, + entity_category=EntityCategory.CONFIG, + icon="mdi:water-thermometer", + api_descriptor=FlagRegisterInputDescriptor(9, 4), + ), + # high byte + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_LEGIO_SETTINGS_INTERVAL_DAILY, + entity_category=EntityCategory.CONFIG, + icon="mdi:home-clock", + api_descriptor=FlagRegisterInputDescriptor(9, 8), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_LEGIO_SETTINGS_INTERVAL_WEEKLY, + entity_category=EntityCategory.CONFIG, + icon="mdi:home-clock", + api_descriptor=FlagRegisterInputDescriptor(9, 9), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_LEGIO_SETTINGS_INTERVAL_FORTNIGHTLY, + entity_category=EntityCategory.CONFIG, + icon="mdi:home-clock", + api_descriptor=FlagRegisterInputDescriptor(9, 10), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_LEGIO_SETTINGS_INTERVAL_MONTHLY, + entity_category=EntityCategory.CONFIG, + icon="mdi:home-clock", + api_descriptor=FlagRegisterInputDescriptor(9, 11), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_LEGIO_SETTINGS_PREFER_FEEDIN_ENERGY, + entity_category=EntityCategory.CONFIG, + icon="mdi:solar-power", + api_descriptor=FlagRegisterInputDescriptor(9, 12), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_LEGIO_SETTINGS_PROTECTION_ENABLED, + entity_category=EntityCategory.CONFIG, + icon="mdi:shield-sun", + api_descriptor=FlagRegisterInputDescriptor(9, 13), + ), + ### legio settings register - end + ### house type settings register - begin + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_HOUSE_TYPE_SINGLE_FAMILY_HOUSE, + entity_category=EntityCategory.CONFIG, + icon="mdi:home", + api_descriptor=FlagRegisterInputDescriptor(20, 0), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_HOUSE_TYPE_TWO_FAMILY_HOUSE, + entity_category=EntityCategory.CONFIG, + icon="mdi:home-group", + api_descriptor=FlagRegisterInputDescriptor(20, 1), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_HOUSE_TYPE_APPARTMENT_BUILDING, + entity_category=EntityCategory.CONFIG, + icon="mdi:floor-plan", + api_descriptor=FlagRegisterInputDescriptor(20, 2), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_HOUSE_TYPE_COMMERCIAL_BUILDING, + entity_category=EntityCategory.CONFIG, + icon="mdi:office-building", + api_descriptor=FlagRegisterInputDescriptor(20, 7), + ), + ### house type settings register - end + ### Summer time int 1/0 as bool + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_SUMMER_TIME_ENABLED, + entity_category=EntityCategory.CONFIG, + icon="mdi:calendar-clock", + api_descriptor=ByteRegisterInputDescriptor(42), + ), + ### rtu settings register - begin + # low byte + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_RTU_SEND_TWO_STOP_BITS, + entity_category=EntityCategory.CONFIG, + icon="mdi:protocol", + api_descriptor=FlagRegisterInputDescriptor(49, 0), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_RTU_SEND_PARITY_EVEN, + entity_category=EntityCategory.CONFIG, + icon="mdi:protocol", + api_descriptor=FlagRegisterInputDescriptor(49, 1), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_RTU_SEND_PARITY_ODD, + entity_category=EntityCategory.CONFIG, + icon="mdi:protocol", + api_descriptor=FlagRegisterInputDescriptor(49, 2), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_RTU_SLAVE_MODE_ACTIVE, + entity_category=EntityCategory.CONFIG, + icon="mdi:protocol", + api_descriptor=FlagRegisterInputDescriptor(49, 7), + ), + # high byte + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_RTU_MASTER_MODE_ACTIVE, + entity_category=EntityCategory.CONFIG, + icon="mdi:protocol", + api_descriptor=FlagRegisterInputDescriptor(49, 15), + ), + ### rtu settings register - end + ### temperature settings register - begin + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_USE_INTERNAL_TEMP_SENSOR, + entity_category=EntityCategory.CONFIG, + icon="mdi:thermometer-water", + api_descriptor=FlagRegisterInputDescriptor(94, 0), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_USE_EXTERNAL_TEMP_SENSOR1, + entity_category=EntityCategory.CONFIG, + icon="mdi:thermometer-water", + api_descriptor=FlagRegisterInputDescriptor(94, 1), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_USE_EXTERNAL_TEMP_SENSOR2, + entity_category=EntityCategory.CONFIG, + icon="mdi:thermometer-water", + api_descriptor=FlagRegisterInputDescriptor(94, 2), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_USE_EXTERNAL_TEMP_SENSOR3, + entity_category=EntityCategory.CONFIG, + icon="mdi:thermometer-water", + api_descriptor=FlagRegisterInputDescriptor(94, 3), + ), + AskoheatSwitchEntityDescription( + key=SwitchAttrKey.CON_USE_EXTERNAL_TEMP_SENSOR4, + entity_category=EntityCategory.CONFIG, + icon="mdi:thermometer-water", + api_descriptor=FlagRegisterInputDescriptor(94, 4), + ), + ### temperature settings register - end + ], ) diff --git a/custom_components/askoheat/const.py b/custom_components/askoheat/const.py index f9a1c25..54e4919 100644 --- a/custom_components/askoheat/const.py +++ b/custom_components/askoheat/const.py @@ -165,13 +165,13 @@ class SwitchAttrKey(StrEnum): CON_EMERGENCY_MODE_ENABLED = "emergency_mode_enabled" # high byte CON_LOW_TARIFF_OPTION_ENABLED = "low_tariff_option_enabled" - CON_HOLD_MINIMAL_TEMPERATURE_ENABELD = "hold_minimal_temperature_enabled" + CON_HOLD_MINIMAL_TEMPERATURE_ENABLED = "hold_minimal_temperature_enabled" CON_SOFTWARE_CONTROL_SMA_SEMP_ENABLED = "sw_control_sma_semp_enabled" CON_SOFTWARE_CONTROL_SENEC_HOME_ENABLED = "sw_control_senec_home_enabled" # from input settings register -- end # from auto heater off settings register -- begin - CON_AUTO_OFF_ENABLED = "auto_off_enabled" + CON_AUTO_OFF_MODBUS_TIMEOUT_ENABLED = "auto_off_modbus_timeout_enabled" CON_RESTART_IF_ENERGYMANAGER_CONNECTION_LOST = "restart_if_em_connection_lost" CON_AUTO_OFF_MODBUS_ENABLED = "auto_off_modbus_enabled" CON_AUTO_OFF_ANALOG_INPUT_ENABLED = "auto_off_analog_input_enabled" @@ -231,7 +231,7 @@ class SwitchAttrKey(StrEnum): CON_HOUSE_TYPE_COMMERCIAL_BUILDING = "house_type_commercial_building" # from house type register -- end - CON_SUMMERTIME_ENABLED = "summertime_enabled" + CON_SUMMER_TIME_ENABLED = "summer_time_enabled" # from rtu settings register -- begin # low byte diff --git a/custom_components/askoheat/model.py b/custom_components/askoheat/model.py index 92e2a76..63b53c6 100644 --- a/custom_components/askoheat/model.py +++ b/custom_components/askoheat/model.py @@ -71,7 +71,9 @@ def data_key(self) -> str: @dataclass(frozen=True) class AskoheatSwitchEntityDescription( - AskoheatEntityDescription[SwitchAttrKey, FlagRegisterInputDescriptor], + AskoheatEntityDescription[ + SwitchAttrKey, FlagRegisterInputDescriptor | ByteRegisterInputDescriptor + ], SwitchEntityDescription, ): """Class describing Askoheat switch entities.""" diff --git a/custom_components/askoheat/switch.py b/custom_components/askoheat/switch.py index d1b5f54..65f6fd4 100644 --- a/custom_components/askoheat/switch.py +++ b/custom_components/askoheat/switch.py @@ -7,6 +7,7 @@ from homeassistant.components.switch import ENTITY_ID_FORMAT, SwitchEntity from homeassistant.core import callback +from custom_components.askoheat.api_conf_desc import CONF_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.api_ema_desc import EMA_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.const import LOGGER from custom_components.askoheat.model import AskoheatSwitchEntityDescription @@ -34,6 +35,13 @@ async def async_setup_entry( ) for entity_description in EMA_REGISTER_BLOCK_DESCRIPTOR.switches ) + async_add_entities( + AskoHeatSwitch( + coordinator=entry.runtime_data.config_coordinator, + entity_description=entity_description, + ) + for entity_description in CONF_REGISTER_BLOCK_DESCRIPTOR.switches + ) class AskoHeatSwitch(AskoheatEntity[AskoheatSwitchEntityDescription], SwitchEntity):