From 69ee62026cb68b600f68eb64316697dea5997021 Mon Sep 17 00:00:00 2001 From: Roger Gonzalez Date: Sat, 23 Sep 2023 21:09:38 -0300 Subject: [PATCH] Cleaned up code, working now! --- custom_components/ute/sensor.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/custom_components/ute/sensor.py b/custom_components/ute/sensor.py index 10eb635..9ff5a46 100644 --- a/custom_components/ute/sensor.py +++ b/custom_components/ute/sensor.py @@ -34,21 +34,26 @@ def setup_platform( email = config[CONF_EMAIL] phone_number = config[CONF_PHONE_NUMBER] - client = UTEClient(email, phone_number) + try: + client = UTEClient(email, phone_number) + except Exception: + _LOGGER.error("Could not connect to UTE") + return + add_entities([UTESensor(client)], True) class UTESensor(SensorEntity): """Representation of a UTE sensor.""" - _attr_name = "UTE Uruguay Client" + _attr_name = "Current power usage" _attr_icon = "lightning-bolt" _attr_native_unit_of_measurement = UnitOfPower.WATT _attr_device_class = SensorDeviceClass.ENERGY - def __init__(self, ute: UTEClient): + def __init__(self, client: UTEClient): super().__init__() - self.ute = ute + self.client = client self._state = None self._available = True self._name = "Current energy usage"