Cleaned up code, working now!

This commit is contained in:
Roger Gonzalez 2023-09-23 21:09:38 -03:00
parent 5c4804bfde
commit 69ee62026c
Signed by: rogs
GPG Key ID: C7ECE9C6C36EC2E6

View File

@ -34,21 +34,26 @@ def setup_platform(
email = config[CONF_EMAIL] email = config[CONF_EMAIL]
phone_number = config[CONF_PHONE_NUMBER] 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) add_entities([UTESensor(client)], True)
class UTESensor(SensorEntity): class UTESensor(SensorEntity):
"""Representation of a UTE sensor.""" """Representation of a UTE sensor."""
_attr_name = "UTE Uruguay Client" _attr_name = "Current power usage"
_attr_icon = "lightning-bolt" _attr_icon = "lightning-bolt"
_attr_native_unit_of_measurement = UnitOfPower.WATT _attr_native_unit_of_measurement = UnitOfPower.WATT
_attr_device_class = SensorDeviceClass.ENERGY _attr_device_class = SensorDeviceClass.ENERGY
def __init__(self, ute: UTEClient): def __init__(self, client: UTEClient):
super().__init__() super().__init__()
self.ute = ute self.client = client
self._state = None self._state = None
self._available = True self._available = True
self._name = "Current energy usage" self._name = "Current energy usage"