From 77fabdac686f29e851b37508a19709a4c1e61a56 Mon Sep 17 00:00:00 2001 From: scottyphillips Date: Fri, 11 Mar 2022 10:41:46 +1100 Subject: [PATCH] initial support for solar generation --- custom_components/echonetlite/__init__.py | 10 ++++-- custom_components/echonetlite/const.py | 36 ++++++++++++++++++++- custom_components/echonetlite/manifest.json | 4 +-- custom_components/echonetlite/sensor.py | 2 ++ 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/custom_components/echonetlite/__init__.py b/custom_components/echonetlite/__init__.py index 7d99c19..559dc30 100644 --- a/custom_components/echonetlite/__init__.py +++ b/custom_components/echonetlite/__init__.py @@ -55,6 +55,9 @@ ENL_STATUS, ENL_BRIGHTNESS, ENL_COLOR_TEMP ] +# fix later +_0287_API_CONNECTOR_DEFAULT_FLAGS = [ENL_STATUS, 0xC0, 0xC1, 0xC2, 0xC5, 0xC6, 0xC7, 0xC8] + async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: entry.async_on_unload(entry.add_update_listener(update_listener)) host = None @@ -188,12 +191,15 @@ def __init__(self, instance, api, entry): # Detect HVAC - eventually we will use factory here. self._update_flags_full_list = [] flags = [] - if self._eojgc == 1 and self._eojcc == 48: + if self._eojgc == 0x01 and self._eojcc == 0x30: _LOGGER.debug(f"Starting ECHONETLite HomeAirConditioner instance at {self._host}") flags = HVAC_API_CONNECTOR_DEFAULT_FLAGS - elif self._eojgc == 2 and self._eojcc == 144: + elif self._eojgc == 0x02 and self._eojcc == 0x90: _LOGGER.debug(f"Starting ECHONETLite GeneralLighting instance at {self._host}") flags = LIGHT_API_CONNECTOR_DEFAULT_FLAGS + elif self._eojgc == 0x02 and self._eojcc == 0x87: + _LOGGER.debug(f"Starting ECHONETLite DistributionPanelMeter instance at {self._host}") + flags = _0287_API_CONNECTOR_DEFAULT_FLAGS else: _LOGGER.debug(f"Starting ECHONETLite Generic instance for {self._eojgc}-{self._eojcc}-{self._eojci} at {self._host}") flags = [ENL_STATUS] diff --git a/custom_components/echonetlite/const.py b/custom_components/echonetlite/const.py index 5fd6e9e..2e49712 100644 --- a/custom_components/echonetlite/const.py +++ b/custom_components/echonetlite/const.py @@ -1,5 +1,5 @@ """Constants for the echonetlite integration.""" -from homeassistant.const import CONF_ICON, CONF_TYPE, DEVICE_CLASS_POWER, DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_ENERGY, DEVICE_CLASS_HUMIDITY +from homeassistant.const import CONF_ICON, CONF_TYPE, DEVICE_CLASS_POWER, DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_ENERGY, DEVICE_CLASS_HUMIDITY, PERCENTAGE from homeassistant.components.sensor import ATTR_STATE_CLASS, STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL_INCREASING from pychonet.HomeAirConditioner import ( ENL_FANSPEED, @@ -80,6 +80,40 @@ } } }, + 0x02: { + 0x87:{ + 0xE0: { + CONF_ICON: "mdi:flash", + CONF_TYPE: DEVICE_CLASS_POWER, + CONF_STATE_CLASS: STATE_CLASS_MEASUREMENT + }, + 0xE1: { + CONF_ICON: "mdi:flash", + CONF_TYPE: DEVICE_CLASS_ENERGY, + CONF_STATE_CLASS: STATE_CLASS_TOTAL_INCREASING + }, + 0xE5: { + CONF_ICON: "mdi:percent", + CONF_TYPE: PERCENTAGE, + CONF_STATE_CLASS: STATE_CLASS_MEASUREMENT + }, + 0xE6: { + CONF_ICON: "mdi:flash", + CONF_TYPE: DEVICE_CLASS_POWER, + CONF_STATE_CLASS: STATE_CLASS_MEASUREMENT + }, + 0xE8: { + CONF_ICON: "mdi:flash", + CONF_TYPE: DEVICE_CLASS_POWER, + CONF_STATE_CLASS: STATE_CLASS_MEASUREMENT + }, + 0xE9: { + CONF_ICON: "mdi:flash", + CONF_TYPE: DEVICE_CLASS_POWER, + CONF_STATE_CLASS: STATE_CLASS_MEASUREMENT + } + } + } 'default': { CONF_ICON: None, CONF_TYPE: None, diff --git a/custom_components/echonetlite/manifest.json b/custom_components/echonetlite/manifest.json index 09b26b2..5b52de4 100644 --- a/custom_components/echonetlite/manifest.json +++ b/custom_components/echonetlite/manifest.json @@ -5,13 +5,13 @@ "config_flow": true, "documentation": "https://www.github.com/scottyphillips/echonetlite_homeassistant", "requirements": [ - "pychonet==2.1.1", + "pychonet==2.1.6", "aio-udp-server" ], "dependencies": [], "codeowners": [ "@scottyphillips" ], - "version": "3.4.1", + "version": "3.4.2", "iot_class": "local_polling" } diff --git a/custom_components/echonetlite/sensor.py b/custom_components/echonetlite/sensor.py index 216aba1..babd9fb 100644 --- a/custom_components/echonetlite/sensor.py +++ b/custom_components/echonetlite/sensor.py @@ -108,6 +108,8 @@ def __init__(self, instance, op_code, attributes, name=None) -> None: self._unit_of_measurement = POWER_WATT elif self._sensor_attributes[CONF_TYPE] == DEVICE_CLASS_HUMIDITY: self._unit_of_measurement = PERCENTAGE + elif self._sensor_attributes[CONF_TYPE] == PERCENTAGE: + self._unit_of_measurement = PERCENTAGE else: self._unit_of_measurement = None