Skip to content

Commit

Permalink
Support CONF_DISABLED_DEFAULT
Browse files Browse the repository at this point in the history
  • Loading branch information
nao-pon committed Mar 22, 2024
1 parent 380d184 commit 722e9f1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
11 changes: 10 additions & 1 deletion custom_components/echonetlite/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion custom_components/echonetlite/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
)
Expand Down Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion custom_components/echonetlite/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
)
Expand Down Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion custom_components/echonetlite/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 722e9f1

Please sign in to comment.