diff --git a/custom_components/garo_wallbox/__init__.py b/custom_components/garo_wallbox/__init__.py index 610c2d2..b5278bf 100644 --- a/custom_components/garo_wallbox/__init__.py +++ b/custom_components/garo_wallbox/__init__.py @@ -13,12 +13,11 @@ from homeassistant.const import ( ATTR_NAME, CONF_HOST, - CONF_PORT, - CONF_SSL, - CONF_VERIFY_SSL, + CONF_NAME, ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady +from homeassistant.helpers import device_registry as dr from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.entity import Entity from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed @@ -43,7 +42,7 @@ async def async_setup(hass: HomeAssistant, config: Dict) -> bool: async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry): conf = entry.data - device = await garo_setup(hass, conf[CONF_HOST]) + device = await garo_setup(hass, conf[CONF_HOST], conf[CONF_NAME]) if not device: return False hass.data.setdefault(DOMAIN, {}).update({entry.entry_id: device}) @@ -51,6 +50,9 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry): hass.async_create_task( hass.config_entries.async_forward_entry_setup(entry, component) ) + + """device_registry = await dr.async_get_registry(hass) + device_registry.async_get_or_create(**device.device_info)""" return True async def async_unload_entry(hass, config_entry): @@ -66,12 +68,12 @@ async def async_unload_entry(hass, config_entry): hass.data.pop(DOMAIN) return True -async def garo_setup(hass, host): +async def garo_setup(hass, host, name): """Create a Garo instance only once.""" session = hass.helpers.aiohttp_client.async_get_clientsession() try: with timeout(TIMEOUT): - device = GaroDevice(host, session) + device = GaroDevice(host, name, session) await device.init() except asyncio.TimeoutError: _LOGGER.debug("Connection to %s timed out", host) diff --git a/custom_components/garo_wallbox/config_flow.py b/custom_components/garo_wallbox/config_flow.py index 2e954dd..ff6a68e 100644 --- a/custom_components/garo_wallbox/config_flow.py +++ b/custom_components/garo_wallbox/config_flow.py @@ -7,7 +7,7 @@ import voluptuous as vol from homeassistant import config_entries -from homeassistant.const import CONF_HOST +from homeassistant.const import CONF_HOST, CONF_NAME from .garo import GaroDevice @@ -22,21 +22,21 @@ class FlowHandler(config_entries.ConfigFlow): VERSION = 1 CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL - async def _create_entry(self, host): + async def _create_entry(self, host, name): """Register new entry.""" # Check if ip already is registered for entry in self._async_current_entries(): if entry.data[KEY_IP] == host: return self.async_abort(reason="already_configured") - return self.async_create_entry(title=host, data={CONF_HOST: host}) + return self.async_create_entry(title=host, data={CONF_HOST: host, CONF_NAME: name}) - async def _create_device(self, host): + async def _create_device(self, host, name): """Create device.""" try: device = GaroDevice( - host, self.hass.helpers.aiohttp_client.async_get_clientsession() + host, name, self.hass.helpers.aiohttp_client.async_get_clientsession() ) with timeout(TIMEOUT): await device.init() @@ -49,24 +49,27 @@ async def _create_device(self, host): _LOGGER.exception("Unexpected error creating device") return self.async_abort(reason="device_fail") - return await self._create_entry(host) + return await self._create_entry(host, name) async def async_step_user(self, user_input=None): """User initiated config flow.""" if user_input is None: return self.async_show_form( - step_id="user", data_schema=vol.Schema({vol.Required(CONF_HOST): str}) + step_id="user", data_schema=vol.Schema({ + vol.Required(CONF_HOST): str, + vol.Optional(CONF_NAME): str + }) ) - return await self._create_device(user_input[CONF_HOST]) + return await self._create_device(user_input[CONF_HOST], user_input[CONF_NAME]) async def async_step_import(self, user_input): """Import a config entry.""" host = user_input.get(CONF_HOST) if not host: return await self.async_step_user() - return await self._create_device(host) + return await self._create_device(host, user_input[CONF_NAME]) async def async_step_discovery(self, user_input): """Initialize step from discovery.""" _LOGGER.info("Discovered device: %s", user_input) - return await self._create_entry(user_input[KEY_IP]) + return await self._create_entry(user_input[KEY_IP], None) diff --git a/custom_components/garo_wallbox/const.py b/custom_components/garo_wallbox/const.py index f3ec97e..21ba295 100644 --- a/custom_components/garo_wallbox/const.py +++ b/custom_components/garo_wallbox/const.py @@ -89,5 +89,13 @@ 80: 'GLBPDC-T222WO', 81: 'GLBPDC-T222FC', 82: 'GLBDCM-T274FC', - 83: 'GLBDCW-T237FC-A VO' + 83: 'GLBDCW-T237FC-A VO', + 84: 'GLBDCWM-T137FC-A', + 85: 'GLBDCWM-T237FC-A', + 86: 'GGLBDCWM-T274WO-A', + 87: 'GLBDCWM-T222FC', + 88: 'GLBDCWM-T222WO', + 89: 'GLBDCWM-T274FC-A', + 90: 'GLBDCW-T211FC', + 91: 'GLBDCW-T222FC' } \ No newline at end of file diff --git a/custom_components/garo_wallbox/garo.py b/custom_components/garo_wallbox/garo.py index 27e02cd..bd584b3 100644 --- a/custom_components/garo_wallbox/garo.py +++ b/custom_components/garo_wallbox/garo.py @@ -5,7 +5,7 @@ import asyncio from homeassistant.util import Throttle -from .const import GARO_PRODUCT_MAP +from .const import GARO_PRODUCT_MAP, DOMAIN current_milli_time = lambda: int(round(time.time() * 1000)) @@ -42,14 +42,17 @@ class Status(Enum): class GaroDevice: - def __init__(self, host, session): + def __init__(self, host, name, session): self.host = host + self.name = name self._status = None self._session = session async def init(self): await self.async_get_info() self.id = 'garo_{}'.format(self.info.serial) + if self.name is None: + self.name = f'{self.info.model} ({self.host})' await self.async_update() @property @@ -60,10 +63,10 @@ def status(self): def device_info(self): """Return a device description for device registry.""" return { - "identifieres": self.id, + "identifiers": { (DOMAIN, self.id) }, "manufacturer": "Garo", "model": self.info.model, - "name": self.host + "name": self.name, } def _request(self, parameter_list): diff --git a/custom_components/garo_wallbox/sensor.py b/custom_components/garo_wallbox/sensor.py index 1dfc0f7..70a4dcc 100644 --- a/custom_components/garo_wallbox/sensor.py +++ b/custom_components/garo_wallbox/sensor.py @@ -15,7 +15,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= async def async_setup_entry(hass, entry, async_add_entities): - """Set up Daikin climate based on config_entry.""" + """Set up using config_entry.""" device = hass.data[GARO_DOMAIN].get(entry.entry_id) async_add_entities([ GaroSensor(device, 'Status', 'status'), @@ -25,14 +25,16 @@ async def async_setup_entry(hass, entry, async_add_entities): GaroSensor(device, "Phases", 'nr_of_phases'), GaroSensor(device, "Current Limit", 'current_limit', 'A'), GaroSensor(device, "Pilot Level", 'pilot_level', 'A'), - GaroSensor(device, "Temperature", 'current_temperature', TEMP_CELSIUS) + GaroSensor(device, "Session Energy", 'acc_session_energy', "Wh"), + GaroSensor(device, "Total Energy", 'latest_reading', "Wh"), + GaroSensor(device, "Temperature", 'current_temperature', TEMP_CELSIUS), ]) class GaroSensor(Entity): def __init__(self, device: GaroDevice, name, sensor, unit = None): """Initialize the sensor.""" self._device = device - self._name = f"{device.id} {name}" + self._name = f"{device.name} {name}" self._sensor = sensor self._unit = unit diff --git a/custom_components/garo_wallbox/strings.json b/custom_components/garo_wallbox/strings.json index 5987b35..6275b29 100644 --- a/custom_components/garo_wallbox/strings.json +++ b/custom_components/garo_wallbox/strings.json @@ -4,7 +4,7 @@ "user": { "title": "Configure Garo Wallbox", "description": "Enter IP address of your Garo Wallbox.", - "data": { "host": "Host" } + "data": { "host": "Host", "name": "Friendly name" } } }, "abort": { diff --git a/custom_components/garo_wallbox/translations/en.json b/custom_components/garo_wallbox/translations/en.json index 5987b35..6275b29 100644 --- a/custom_components/garo_wallbox/translations/en.json +++ b/custom_components/garo_wallbox/translations/en.json @@ -4,7 +4,7 @@ "user": { "title": "Configure Garo Wallbox", "description": "Enter IP address of your Garo Wallbox.", - "data": { "host": "Host" } + "data": { "host": "Host", "name": "Friendly name" } } }, "abort": {