diff --git a/custom_components/echonetlite/number.py b/custom_components/echonetlite/number.py index 2d3cfe8..a410c4b 100644 --- a/custom_components/echonetlite/number.py +++ b/custom_components/echonetlite/number.py @@ -11,12 +11,14 @@ from pychonet.lib.eojx import EOJX_CLASS from . import get_name_by_epc_code, get_unit_by_devise_class, get_device_name from .const import ( + CONF_DISABLED_DEFAULT, DOMAIN, CONF_FORCE_POLLING, ENL_OP_CODES, CONF_AS_ZERO, CONF_MAX_OPC, CONF_BYTE_LENGTH, + NON_SETUP_SINGLE_ENYITY, TYPE_NUMBER, ) @@ -30,7 +32,10 @@ async def async_setup_entry(hass, config, async_add_entities, discovery_info=Non eojcc = entity["instance"]["eojcc"] _enl_op_codes = ENL_OP_CODES.get(eojgc, {}).get(eojcc, {}) # configure select entities by looking up full ENL_OP_CODE dict - for op_code in entity["instance"]["setmap"]: + for op_code in list( + set(entity["instance"]["setmap"]) + - NON_SETUP_SINGLE_ENYITY.get(eojgc, {}).get(eojcc, set()) + ): if TYPE_NUMBER in _enl_op_codes.get(op_code, {}).keys(): entities.append( EchonetNumber( @@ -86,6 +91,10 @@ def __init__(self, hass, connector, config, code, options): self._attr_should_poll = True self._attr_available = True + self._attr_entity_registry_enabled_default = not bool( + options.get(CONF_DISABLED_DEFAULT) + ) + self.update_option_listener() @property diff --git a/custom_components/echonetlite/select.py b/custom_components/echonetlite/select.py index 8da6313..c398585 100644 --- a/custom_components/echonetlite/select.py +++ b/custom_components/echonetlite/select.py @@ -3,6 +3,7 @@ from homeassistant.components.select import SelectEntity from . import get_name_by_epc_code, get_device_name from .const import ( + CONF_DISABLED_DEFAULT, DOMAIN, CONF_FORCE_POLLING, ENL_OP_CODES, @@ -26,7 +27,10 @@ async def async_setup_entry(hass, config, async_add_entities, discovery_info=Non eojcc, set() ) # configure select entities by looking up full ENL_OP_CODE dict - for op_code in entity["instance"]["setmap"]: + for op_code in list( + set(entity["instance"]["setmap"]) + - NON_SETUP_SINGLE_ENYITY.get(eojgc, {}).get(eojcc, set()) + ): epc_function_data = entity["echonetlite"]._instance.EPC_FUNCTIONS.get( op_code, None ) @@ -91,6 +95,10 @@ def __init__(self, hass, connector, config, code, options): self._attr_available = True self._attr_force_update = False + self._attr_entity_registry_enabled_default = not bool( + options.get(CONF_DISABLED_DEFAULT) + ) + self.update_option_listener() @property diff --git a/custom_components/echonetlite/switch.py b/custom_components/echonetlite/switch.py index 6d3d5da..cb21024 100644 --- a/custom_components/echonetlite/switch.py +++ b/custom_components/echonetlite/switch.py @@ -4,12 +4,14 @@ from homeassistant.components.switch import SwitchEntity from . import get_name_by_epc_code, get_device_name from .const import ( + CONF_DISABLED_DEFAULT, DOMAIN, ENL_OP_CODES, CONF_ON_VALUE, CONF_OFF_VALUE, DATA_STATE_ON, DATA_STATE_OFF, + NON_SETUP_SINGLE_ENYITY, SWITCH_POWER, CONF_ENSURE_ON, TYPE_SWITCH, @@ -30,7 +32,10 @@ async def async_setup_entry(hass, config, async_add_entities, discovery_info=Non set_enl_status = False _enl_op_codes = ENL_OP_CODES.get(eojgc, {}).get(eojcc, {}) # configure switch entities by looking up full ENL_OP_CODE dict - for op_code in entity["instance"]["setmap"]: + for op_code in list( + set(entity["instance"]["setmap"]) + - NON_SETUP_SINGLE_ENYITY.get(eojgc, {}).get(eojcc, set()) + ): epc_function_data = entity["echonetlite"]._instance.EPC_FUNCTIONS.get( op_code, None ) @@ -136,6 +141,10 @@ def __init__(self, hass, connector, config, code, options): self._attr_should_poll = True self._attr_available = True + self._attr_entity_registry_enabled_default = not bool( + options.get(CONF_DISABLED_DEFAULT) + ) + self.update_option_listener() @property diff --git a/custom_components/echonetlite/time.py b/custom_components/echonetlite/time.py index 9ee6910..579643f 100644 --- a/custom_components/echonetlite/time.py +++ b/custom_components/echonetlite/time.py @@ -6,10 +6,12 @@ from homeassistant.exceptions import InvalidStateError from . import get_name_by_epc_code, get_device_name from .const import ( + CONF_DISABLED_DEFAULT, DOMAIN, CONF_FORCE_POLLING, ENL_OP_CODES, ENL_SUPER_CODES, + NON_SETUP_SINGLE_ENYITY, TYPE_TIME, ) from pychonet.lib.eojx import EOJX_CLASS @@ -25,7 +27,10 @@ async def async_setup_entry(hass, config, async_add_entities, discovery_info=Non eojcc = entity["instance"]["eojcc"] _enl_op_codes = ENL_OP_CODES.get(eojgc, {}).get(eojcc, {}) | ENL_SUPER_CODES # configure select entities by looking up full ENL_OP_CODE dict - for op_code in entity["instance"]["setmap"]: + for op_code in list( + set(entity["instance"]["setmap"]) + - NON_SETUP_SINGLE_ENYITY.get(eojgc, {}).get(eojcc, set()) + ): epc_function_data = entity["echonetlite"]._instance.EPC_FUNCTIONS.get( op_code, None ) @@ -70,6 +75,10 @@ def __init__(self, hass, connector, config, code, options, device_name=None): self._attr_should_poll = True self._attr_available = True + self._attr_entity_registry_enabled_default = not bool( + options.get(CONF_DISABLED_DEFAULT) + ) + self.update_option_listener() @property