Skip to content

Commit

Permalink
Adjusting automatic configuration of input entities
Browse files Browse the repository at this point in the history
  • Loading branch information
nao-pon committed Jan 31, 2024
1 parent e8f5382 commit 1318a0c
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 227 deletions.
2 changes: 1 addition & 1 deletion custom_components/echonetlite/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
# CONF_MINIMUM: 0x0, # Minimum value
# CONF_MAXIMUM: 0x32, # Maximum value
# CONF_MAX_OPC: None, # OPC of max value
# CONF_BYTE_LENGTH: 0x0 # Data byte length
# CONF_BYTE_LENGTH: 0x1, # Data byte length
# TYPE_SWITCH: { # Additional switch
# CONF_NAME: "Auto", # Additionale name
# CONF_SERVICE_DATA: {DATA_STATE_ON: 23, DATA_STATE_OFF: 22},
Expand Down
28 changes: 13 additions & 15 deletions custom_components/echonetlite/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,20 @@ async def async_setup_entry(hass, config, async_add_entities, discovery_info=Non
for entity in hass.data[DOMAIN][config.entry_id]:
eojgc = entity["instance"]["eojgc"]
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"]:
if eojgc in ENL_OP_CODES.keys():
if eojcc in ENL_OP_CODES[eojgc].keys():
if op_code in ENL_OP_CODES[eojgc][eojcc].keys():
if TYPE_NUMBER in ENL_OP_CODES[eojgc][eojcc][op_code].keys():
entities.append(
EchonetNumber(
hass,
entity["echonetlite"],
config,
op_code,
ENL_OP_CODES[eojgc][eojcc][op_code],
entity["echonetlite"]._name or config.title,
)
)
if TYPE_NUMBER in _enl_op_codes.get(op_code, {}).keys():
entities.append(
EchonetNumber(
hass,
entity["echonetlite"],
config,
op_code,
ENL_OP_CODES[eojgc][eojcc][op_code],
entity["echonetlite"]._name or config.title,
)
)

async_add_entities(entities, True)

Expand All @@ -71,7 +69,7 @@ def __init__(self, hass, connector, config, code, options, name=None):
self._options = options[TYPE_NUMBER]
self._as_zero = int(options[TYPE_NUMBER].get(CONF_AS_ZERO, 0))
self._conf_max = int(options[TYPE_NUMBER][CONF_MAXIMUM])
self._byte_length = int(options[TYPE_NUMBER].get(CONF_BYTE_LENGTH, 0))
self._byte_length = int(options[TYPE_NUMBER].get(CONF_BYTE_LENGTH, 1))

self._device_name = name
self._attr_device_class = self._options.get(CONF_TYPE, None)
Expand Down
43 changes: 20 additions & 23 deletions custom_components/echonetlite/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,28 @@ async def async_setup_entry(hass, config, async_add_entities, discovery_info=Non
for entity in hass.data[DOMAIN][config.entry_id]:
eojgc = entity["instance"]["eojgc"]
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"]:
if eojgc in ENL_OP_CODES.keys():
if eojcc in ENL_OP_CODES[eojgc].keys():
if op_code in ENL_OP_CODES[eojgc][eojcc].keys():
epc_function_data = entity[
"echonetlite"
]._instance.EPC_FUNCTIONS.get(op_code, None)
if TYPE_SELECT in ENL_OP_CODES[eojgc][eojcc][
op_code
].keys() or (
type(epc_function_data) == list
and type(epc_function_data[1]) == dict
and len(epc_function_data[1]) > 2
):
entities.append(
EchonetSelect(
hass,
entity["echonetlite"],
config,
op_code,
ENL_OP_CODES[eojgc][eojcc][op_code],
entity["echonetlite"]._name or config.title,
)
)
epc_function_data = entity["echonetlite"]._instance.EPC_FUNCTIONS.get(
op_code, None
)
_by_epc_func = (
type(epc_function_data) == list
and type(epc_function_data[1]) == dict
and len(epc_function_data[1]) > 2
)
if _by_epc_func or TYPE_SELECT in _enl_op_codes.get(op_code, {}).keys():
entities.append(
EchonetSelect(
hass,
entity["echonetlite"],
config,
op_code,
_enl_op_codes.get(op_code, {}),
entity["echonetlite"]._name or config.title,
)
)

async_add_entities(entities, True)

Expand Down
Loading

0 comments on commit 1318a0c

Please sign in to comment.