From 31502e960a7f1a96e2286c3301d7a384bf6d376b Mon Sep 17 00:00:00 2001 From: Simone Chemelli Date: Thu, 12 Nov 2020 19:49:06 +0100 Subject: [PATCH] Shelly: minor improvements (#43138) --- homeassistant/components/shelly/__init__.py | 13 ++++++++----- homeassistant/components/shelly/sensor.py | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/shelly/__init__.py b/homeassistant/components/shelly/__init__.py index 6aa08286dc1..14daffb4221 100644 --- a/homeassistant/components/shelly/__init__.py +++ b/homeassistant/components/shelly/__init__.py @@ -54,6 +54,11 @@ async def get_coap_context(hass): return context +def get_device_name(device): + """Naming for device.""" + return device.settings["name"] or device.settings["device"]["hostname"] + + async def async_setup(hass: HomeAssistant, config: dict): """Set up the Shelly component.""" hass.data[DOMAIN] = {DATA_CONFIG_ENTRY: {}} @@ -126,7 +131,7 @@ class ShellyDeviceWrapper(update_coordinator.DataUpdateCoordinator): super().__init__( hass, _LOGGER, - name=device.settings["name"] or device.settings["device"]["hostname"], + name=get_device_name(device), update_interval=timedelta(seconds=update_interval), ) self.hass = hass @@ -186,7 +191,7 @@ class ShellyDeviceRestWrapper(update_coordinator.DataUpdateCoordinator): super().__init__( hass, _LOGGER, - name=device.settings["name"] or device.settings["device"]["hostname"], + name=get_device_name(device), update_interval=timedelta(seconds=REST_SENSORS_UPDATE_INTERVAL), ) self.device = device @@ -195,9 +200,7 @@ class ShellyDeviceRestWrapper(update_coordinator.DataUpdateCoordinator): """Fetch data.""" try: async with async_timeout.timeout(5): - _LOGGER.debug( - "REST update for %s", self.device.settings["device"]["hostname"] - ) + _LOGGER.debug("REST update for %s", get_device_name(self.device)) return await self.device.update_status() except OSError as err: raise update_coordinator.UpdateFailed("Error fetching data") from err diff --git a/homeassistant/components/shelly/sensor.py b/homeassistant/components/shelly/sensor.py index d73d7b5c2d4..5d29aae8d5e 100644 --- a/homeassistant/components/shelly/sensor.py +++ b/homeassistant/components/shelly/sensor.py @@ -124,6 +124,7 @@ SENSORS = { name="Gas Concentration", unit=CONCENTRATION_PARTS_PER_MILLION, value=lambda value: value, + icon="mdi:gauge", # "sensorOp" is "normal" when the Shelly Gas is working properly and taking measurements. available=lambda block: block.sensorOp == "normal", ), @@ -144,7 +145,7 @@ SENSORS = { unit=LIGHT_LUX, device_class=sensor.DEVICE_CLASS_ILLUMINANCE, ), - ("sensor", "tilt"): BlockAttributeDescription(name="tilt", unit=DEGREE), + ("sensor", "tilt"): BlockAttributeDescription(name="Tilt", unit=DEGREE), ("relay", "totalWorkTime"): BlockAttributeDescription( name="Lamp life", unit=PERCENTAGE,