From bea2f4c09b08ee716a0337b539839b618422dcbb Mon Sep 17 00:00:00 2001 From: nao-pon Date: Sun, 12 May 2024 17:07:16 +0900 Subject: [PATCH] Supports Refrigerator --- custom_components/echonetlite/const.py | 191 ++++++++++++++++++++++++ custom_components/echonetlite/number.py | 10 +- custom_components/echonetlite/sensor.py | 6 +- 3 files changed, 204 insertions(+), 3 deletions(-) diff --git a/custom_components/echonetlite/const.py b/custom_components/echonetlite/const.py index 20e957b..403ecdd 100644 --- a/custom_components/echonetlite/const.py +++ b/custom_components/echonetlite/const.py @@ -70,6 +70,7 @@ ENL_LVSEEM_INSTANT_ENG, ) from pychonet.lib.const import ENL_CUMULATIVE_POWER, ENL_INSTANTANEOUS_POWER +from pychonet.lib.epc_functions import DATA_STATE_CLOSE, DATA_STATE_OPEN DOMAIN = "echonetlite" CONF_STATE_CLASS = ATTR_STATE_CLASS @@ -997,6 +998,196 @@ }, }, }, + 0x03: { # Cooking/housework-related device class group + 0x7B: { # Refrigerator + 0xB0: { + CONF_ICON: "mdi:door", + CONF_ICONS: { + DATA_STATE_OPEN: "mdi:door-open", + DATA_STATE_CLOSE: "mdi:door-closed", + }, + }, # "Door open/close status", + 0xB1: { + CONF_ICON: "mdi:door", + CONF_ICONS: { + DATA_STATE_OPEN: "mdi:door-open", + DATA_STATE_CLOSE: "mdi:door-closed", + }, + }, # "Door open warning", + 0xB2: { + CONF_ICON: "mdi:door", + CONF_ICONS: { + DATA_STATE_OPEN: "mdi:door-open", + DATA_STATE_CLOSE: "mdi:door-closed", + }, + }, # "Refrigerator compartment door status", + 0xB3: { + CONF_ICON: "mdi:door", + CONF_ICONS: { + DATA_STATE_OPEN: "mdi:door-open", + DATA_STATE_CLOSE: "mdi:door-closed", + }, + }, # "Freezer compartment door status", + 0xB4: { + CONF_ICON: "mdi:door", + CONF_ICONS: { + DATA_STATE_OPEN: "mdi:door-open", + DATA_STATE_CLOSE: "mdi:door-closed", + }, + }, # "Ice compartment door status", + 0xB5: { + CONF_ICON: "mdi:door", + CONF_ICONS: { + DATA_STATE_OPEN: "mdi:door-open", + DATA_STATE_CLOSE: "mdi:door-closed", + }, + }, # "Vegetable compartment door status", + 0xB6: { + CONF_ICON: "mdi:door", + CONF_ICONS: { + DATA_STATE_OPEN: "mdi:door-open", + DATA_STATE_CLOSE: "mdi:door-closed", + }, + }, # "Multi-refrigera-ting mode compartment door", + 0xE0: { + TYPE_DATA_DICT: [ + "refrigerator", + "freezer", + "ice", + "vegetable", + "multi_refrigerating", + ] + }, # "Maximum allowable temperature setting level", + 0xE2: { + CONF_TYPE: SensorDeviceClass.TEMPERATURE, + CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, + TYPE_NUMBER: { + CONF_TYPE: NumberDeviceClass.TEMPERATURE, + CONF_MINIMUM: -127, + CONF_MAXIMUM: 126, + }, + }, # "Refrigerator compartment temperature setting", + 0xE3: { + CONF_TYPE: SensorDeviceClass.TEMPERATURE, + CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, + TYPE_NUMBER: { + CONF_TYPE: NumberDeviceClass.TEMPERATURE, + CONF_MINIMUM: -127, + CONF_MAXIMUM: 126, + }, + }, # "Freezer compartment temperature setting", + 0xE4: { + CONF_TYPE: SensorDeviceClass.TEMPERATURE, + CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, + TYPE_NUMBER: { + CONF_TYPE: NumberDeviceClass.TEMPERATURE, + CONF_MINIMUM: -127, + CONF_MAXIMUM: 126, + }, + }, # "Ice temperature setting", + 0xE5: { + CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, + TYPE_NUMBER: { + CONF_TYPE: NumberDeviceClass.TEMPERATURE, + CONF_MINIMUM: -127, + CONF_MAXIMUM: 126, + }, + CONF_TYPE: SensorDeviceClass.TEMPERATURE, + }, # "Vegetable compartment temperature setting", + 0xE6: { + CONF_TYPE: SensorDeviceClass.TEMPERATURE, + CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, + TYPE_NUMBER: { + CONF_TYPE: NumberDeviceClass.TEMPERATURE, + CONF_MINIMUM: -127, + CONF_MAXIMUM: 126, + }, + }, # "Multi-refrigera-ting mode compartment temperature setting", + 0xE9: { + TYPE_NUMBER: { + CONF_TYPE: NumberDeviceClass.TEMPERATURE, + CONF_MINIMUM: 1, + CONF_MAXIMUM: 0xFF, + CONF_MAX_OPC: {"code": 0xE0, "key": "refrigerator"}, + }, + }, # "Refrigerator compartment temperature level setting", + 0xEA: { + TYPE_NUMBER: { + CONF_TYPE: NumberDeviceClass.TEMPERATURE, + CONF_MINIMUM: 1, + CONF_MAXIMUM: 0xFF, + CONF_MAX_OPC: [0xE0, "freezer"], + }, + }, # "Freezer compartment temperature level setting", + 0xEB: { + TYPE_NUMBER: { + CONF_TYPE: NumberDeviceClass.TEMPERATURE, + CONF_MINIMUM: 1, + CONF_MAXIMUM: 0xFF, + CONF_MAX_OPC: [0xE0, "ice"], + }, + }, # "ice compartment temperature level setting", + 0xEC: { + TYPE_NUMBER: { + CONF_TYPE: NumberDeviceClass.TEMPERATURE, + CONF_MINIMUM: 1, + CONF_MAXIMUM: 0xFF, + CONF_MAX_OPC: [0xE0, "vegetable"], + }, + }, # "Vegetable compartment temperature level setting", + 0xED: { + TYPE_NUMBER: { + CONF_TYPE: NumberDeviceClass.TEMPERATURE, + CONF_MINIMUM: 1, + CONF_MAXIMUM: 0xFF, + CONF_MAX_OPC: [0xE0, "multi_refrigerating"], + }, + }, # "Multi-refrigera-ting mode compartment temperature level setting", + 0xD1: { + CONF_TYPE: SensorDeviceClass.TEMPERATURE, + }, # "Measured refrigerator compartment temperature", + 0xD2: { + CONF_TYPE: SensorDeviceClass.TEMPERATURE, + }, # "Measured freezer compartment temperature", + 0xD3: { + CONF_TYPE: SensorDeviceClass.TEMPERATURE, + }, # "Measured subzero-fresh compartment temperature", + 0xD4: { + CONF_TYPE: SensorDeviceClass.TEMPERATURE, + }, # "Measured vegetable compartment temperature", + 0xD5: { + CONF_TYPE: SensorDeviceClass.TEMPERATURE, + }, # "Measured multi-refrigeratin g mode compartment temperature", + 0xD8: { + TYPE_DATA_DICT: ["maximum_rotation_speed", "rotation_speed"] + }, # "Compressor rotation speed", + 0xDA: { + CONF_TYPE: SensorDeviceClass.CURRENT, + CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, + CONF_MULTIPLIER: 0.1, + }, # "Measured electric current consumption", + 0xDC: { + CONF_TYPE: SensorDeviceClass.POWER, + CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, + }, # "Rated power consumption", + 0xA0: { + CONF_ICON: "mdi:snowflake-check" + }, # "Quick freeze function setting", + 0xA1: { + CONF_ICON: "mdi:fridge-bottom" + }, # "Quick refrigeration function setting", + 0xA4: {CONF_ICON: "mdi:dice-1-outline"}, # "Icemaker setting", + 0xA5: {CONF_ICON: "mdi:dice-1-outline"}, # "Icemaker operation status", + 0xA6: {CONF_ICON: "mdi:water-alert-outline"}, # "Icemaker tank status", + 0xA8: { + CONF_ICON: "mdi:water-thermometer" + }, # "Refrigerator compartment humidification function setting", + 0xA9: { + CONF_ICON: "mdi:water-thermometer" + }, # "Vegetable compartment humidification function setting", + 0xAD: {CONF_ICON: "mdi:scent"}, # "Deodorization function setting", + }, # Refrigerator + }, "default": { CONF_ICON: None, CONF_TYPE: None, diff --git a/custom_components/echonetlite/number.py b/custom_components/echonetlite/number.py index a410c4b..ed16637 100644 --- a/custom_components/echonetlite/number.py +++ b/custom_components/echonetlite/number.py @@ -137,8 +137,14 @@ def get_max_value(self): def get_max_opc_value(self): max_opc_value = None - if self._options.get(CONF_MAX_OPC): - max_opc_value = self._connector._update_data.get(CONF_MAX_OPC) + max_opc = self._options.get(CONF_MAX_OPC) + if max_opc: + if isinstance(max_opc, list): + max_opc_value = self._connector._update_data.get(max_opc[0]).get( + max_opc[1] + ) + else: + max_opc_value = self._connector._update_data.get(max_opc) if max_opc_value != None: max_opc_value = int(max_opc_value) return max_opc_value diff --git a/custom_components/echonetlite/sensor.py b/custom_components/echonetlite/sensor.py index 705e5ca..5d85d25 100644 --- a/custom_components/echonetlite/sensor.py +++ b/custom_components/echonetlite/sensor.py @@ -187,7 +187,10 @@ async def async_setup_entry(hass, config, async_add_entities, discovery_info=Non entity["echonetlite"], config, op_code, - _enl_op_codes[op_code], + _enl_op_codes.get( + op_code, + ENL_OP_CODES["default"] | {CONF_DISABLED_DEFAULT: True}, + ), hass, ) ) @@ -198,6 +201,7 @@ async def async_setup_entry(hass, config, async_add_entities, discovery_info=Non config, op_code, ENL_OP_CODES["default"], + hass, ) ) async_add_entities(entities, True)