1 """Support for UpCloud."""
3 from __future__
import annotations
14 from .const
import DOMAIN
15 from .coordinator
import UpCloudDataUpdateCoordinator
17 _LOGGER = logging.getLogger(__name__)
19 ATTR_CORE_NUMBER =
"core_number"
20 ATTR_HOSTNAME =
"hostname"
21 ATTR_MEMORY_AMOUNT =
"memory_amount"
26 DEFAULT_COMPONENT_NAME =
"UpCloud {}"
28 STATE_MAP = {
"error": STATE_PROBLEM,
"started": STATE_ON,
"stopped": STATE_OFF}
32 """Entity class for UpCloud servers."""
36 coordinator: UpCloudDataUpdateCoordinator,
39 """Initialize the UpCloud server entity."""
45 return self.coordinator.data[self.
uuiduuid]
49 """Return unique ID for the entity."""
54 """Return the name of the component."""
56 return DEFAULT_COMPONENT_NAME.format(self.
_server_server.title)
57 except (AttributeError, KeyError, TypeError):
58 return DEFAULT_COMPONENT_NAME.format(self.
uuiduuid)
62 """Return the icon of this server."""
63 return "mdi:server" if self.
is_onis_on
else "mdi:server-off"
67 """Return true if the server is on."""
69 return STATE_MAP.get(self.
_server_server.state, self.
_server_server.state) == STATE_ON
70 except AttributeError:
75 """Return True if entity is available."""
76 return super().available
and STATE_MAP.get(
78 )
in (STATE_ON, STATE_OFF)
82 """Return the state attributes of the UpCloud server."""
84 x: getattr(self.
_server_server, x,
None)
97 """Return info for device registry."""
98 assert self.coordinator.config_entry
is not None
100 configuration_url=
"https://hub.upcloud.com",
101 model=
"Control Panel",
102 entry_type=DeviceEntryType.SERVICE,
104 (DOMAIN, f
"{self.coordinator.config_entry.data[CONF_USERNAME]}@hub")
106 manufacturer=
"UpCloud Ltd",
upcloud_api.Server _server(self)
DeviceInfo device_info(self)
dict[str, Any] extra_state_attributes(self)
None __init__(self, UpCloudDataUpdateCoordinator coordinator, str uuid)