Use attributes instead of properties for uptime (#52398)

* Use attributes instead of properties for uptime

* add missing types
This commit is contained in:
Yuval Aboulafia 2021-07-01 22:31:30 +03:00 committed by GitHub
parent 8e846164a4
commit 1337dfed8c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -47,25 +47,7 @@ class UptimeSensor(SensorEntity):
def __init__(self, name: str) -> None:
"""Initialize the uptime sensor."""
self._name = name
self._state = dt_util.now().isoformat()
@property
def name(self) -> str:
"""Return the name of the sensor."""
return self._name
@property
def device_class(self) -> str:
"""Return device class."""
return DEVICE_CLASS_TIMESTAMP
@property
def state(self) -> str:
"""Return the state of the sensor."""
return self._state
@property
def should_poll(self) -> bool:
"""Disable polling for this entity."""
return False
self._attr_name: str = name
self._attr_device_class: str = DEVICE_CLASS_TIMESTAMP
self._attr_should_poll: bool = False
self._attr_state: str = dt_util.now().isoformat()