Define ToggleEntity entity attributes as class variables (#51231)
* Define ToggleEntity entity attributes as class variables * Fix upcloud overriding state property * Implement available state for upcloud, to compensate removed state
This commit is contained in:
parent
101864aab8
commit
d51fc5814a
2 changed files with 17 additions and 11 deletions
|
@ -273,18 +273,20 @@ class UpCloudServerEntity(CoordinatorEntity):
|
|||
"""Return the icon of this server."""
|
||||
return "mdi:server" if self.is_on else "mdi:server-off"
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
"""Return state of the server."""
|
||||
try:
|
||||
return STATE_MAP.get(self._server.state, self._server.state)
|
||||
except AttributeError:
|
||||
return None
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if the server is on."""
|
||||
return self.state == STATE_ON
|
||||
try:
|
||||
return STATE_MAP.get(self._server.state, self._server.state) == STATE_ON
|
||||
except AttributeError:
|
||||
return False
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return True if entity is available."""
|
||||
return super().available and STATE_MAP.get(
|
||||
self._server.state, self._server.state
|
||||
) in [STATE_ON, STATE_OFF]
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict[str, Any]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue