Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions homeassistant/components/shelly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def shutdown_listener(ev):
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: {}}
Expand Down Expand Up @@ -126,7 +131,7 @@ def __init__(self, hass, entry, device: aioshelly.Device):
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
Expand Down Expand Up @@ -186,7 +191,7 @@ def __init__(self, hass, device: aioshelly.Device):
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
Expand All @@ -195,9 +200,7 @@ async def _async_update_data(self):
"""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
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/shelly/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
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",
),
Expand All @@ -144,7 +145,7 @@
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,
Expand Down