mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Additional System Bridge Sensors (#50274)
* Update systembridge to 1.1.4 * Update systembridge to 1.1.5 * Names * Add memory sensors * Set icons * Add bios version sensor * Memory used percentage sensor * Add types Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Disable by default * Typing Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
e92516c072
commit
9059ce1c0f
@ -77,6 +77,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||
client.async_get_battery(),
|
||||
client.async_get_cpu(),
|
||||
client.async_get_filesystem(),
|
||||
client.async_get_memory(),
|
||||
client.async_get_network(),
|
||||
client.async_get_os(),
|
||||
client.async_get_processes(),
|
||||
|
@ -1,4 +1,4 @@
|
||||
"""Support for System Bridge sensors."""
|
||||
"""Support for System Bridge binary sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from systembridge import Bridge
|
||||
@ -18,7 +18,7 @@ from .const import DOMAIN
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities
|
||||
) -> None:
|
||||
"""Set up System Bridge sensor based on a config entry."""
|
||||
"""Set up System Bridge binary sensor based on a config entry."""
|
||||
coordinator: DataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
bridge: Bridge = coordinator.data
|
||||
|
||||
@ -27,7 +27,7 @@ async def async_setup_entry(
|
||||
|
||||
|
||||
class BridgeBinarySensor(BridgeDeviceEntity, BinarySensorEntity):
|
||||
"""Defines a System Bridge sensor."""
|
||||
"""Defines a System Bridge binary sensor."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -39,22 +39,22 @@ class BridgeBinarySensor(BridgeDeviceEntity, BinarySensorEntity):
|
||||
device_class: str | None,
|
||||
enabled_by_default: bool,
|
||||
) -> None:
|
||||
"""Initialize System Bridge sensor."""
|
||||
"""Initialize System Bridge binary sensor."""
|
||||
self._device_class = device_class
|
||||
|
||||
super().__init__(coordinator, bridge, key, name, icon, enabled_by_default)
|
||||
|
||||
@property
|
||||
def device_class(self) -> str | None:
|
||||
"""Return the class of this sensor."""
|
||||
"""Return the class of this binary sensor."""
|
||||
return self._device_class
|
||||
|
||||
|
||||
class BridgeBatteryIsChargingBinarySensor(BridgeBinarySensor):
|
||||
"""Defines a Battery is charging sensor."""
|
||||
"""Defines a Battery is charging binary sensor."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge):
|
||||
"""Initialize System Bridge sensor."""
|
||||
"""Initialize System Bridge binary sensor."""
|
||||
super().__init__(
|
||||
coordinator,
|
||||
bridge,
|
||||
|
@ -3,7 +3,7 @@
|
||||
"name": "System Bridge",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/system_bridge",
|
||||
"requirements": ["systembridge==1.1.3"],
|
||||
"requirements": ["systembridge==1.1.5"],
|
||||
"codeowners": ["@timmo001"],
|
||||
"zeroconf": ["_system-bridge._udp.local."],
|
||||
"after_dependencies": ["zeroconf"],
|
||||
|
@ -9,6 +9,7 @@ from systembridge import Bridge
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
DATA_GIGABYTES,
|
||||
DEVICE_CLASS_BATTERY,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
DEVICE_CLASS_TIMESTAMP,
|
||||
@ -51,9 +52,13 @@ async def async_setup_entry(
|
||||
BridgeFilesystemSensor(coordinator, bridge, key)
|
||||
for key, _ in bridge.filesystem.fsSize.items()
|
||||
],
|
||||
BridgeMemoryFreeSensor(coordinator, bridge),
|
||||
BridgeMemoryUsedSensor(coordinator, bridge),
|
||||
BridgeMemoryUsedPercentageSensor(coordinator, bridge),
|
||||
BridgeKernelSensor(coordinator, bridge),
|
||||
BridgeOsSensor(coordinator, bridge),
|
||||
BridgeProcessesLoadSensor(coordinator, bridge),
|
||||
BridgeBiosVersionSensor(coordinator, bridge),
|
||||
]
|
||||
|
||||
if bridge.battery.hasBattery:
|
||||
@ -97,7 +102,7 @@ class BridgeSensor(BridgeDeviceEntity, SensorEntity):
|
||||
class BridgeBatterySensor(BridgeSensor):
|
||||
"""Defines a Battery sensor."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge):
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge) -> None:
|
||||
"""Initialize System Bridge sensor."""
|
||||
super().__init__(
|
||||
coordinator,
|
||||
@ -120,7 +125,7 @@ class BridgeBatterySensor(BridgeSensor):
|
||||
class BridgeBatteryTimeRemainingSensor(BridgeSensor):
|
||||
"""Defines the Battery Time Remaining sensor."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge):
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge) -> None:
|
||||
"""Initialize System Bridge sensor."""
|
||||
super().__init__(
|
||||
coordinator,
|
||||
@ -145,14 +150,14 @@ class BridgeBatteryTimeRemainingSensor(BridgeSensor):
|
||||
class BridgeCpuSpeedSensor(BridgeSensor):
|
||||
"""Defines a CPU speed sensor."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge):
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge) -> None:
|
||||
"""Initialize System Bridge sensor."""
|
||||
super().__init__(
|
||||
coordinator,
|
||||
bridge,
|
||||
"cpu_speed",
|
||||
"CPU Speed",
|
||||
None,
|
||||
"mdi:speedometer",
|
||||
None,
|
||||
FREQUENCY_GIGAHERTZ,
|
||||
True,
|
||||
@ -168,7 +173,7 @@ class BridgeCpuSpeedSensor(BridgeSensor):
|
||||
class BridgeCpuTemperatureSensor(BridgeSensor):
|
||||
"""Defines a CPU temperature sensor."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge):
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge) -> None:
|
||||
"""Initialize System Bridge sensor."""
|
||||
super().__init__(
|
||||
coordinator,
|
||||
@ -191,7 +196,7 @@ class BridgeCpuTemperatureSensor(BridgeSensor):
|
||||
class BridgeCpuVoltageSensor(BridgeSensor):
|
||||
"""Defines a CPU voltage sensor."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge):
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge) -> None:
|
||||
"""Initialize System Bridge sensor."""
|
||||
super().__init__(
|
||||
coordinator,
|
||||
@ -214,14 +219,16 @@ class BridgeCpuVoltageSensor(BridgeSensor):
|
||||
class BridgeFilesystemSensor(BridgeSensor):
|
||||
"""Defines a filesystem sensor."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge, key: str):
|
||||
def __init__(
|
||||
self, coordinator: DataUpdateCoordinator, bridge: Bridge, key: str
|
||||
) -> None:
|
||||
"""Initialize System Bridge sensor."""
|
||||
super().__init__(
|
||||
coordinator,
|
||||
bridge,
|
||||
f"filesystem_{key}",
|
||||
f"{key} Space Used",
|
||||
None,
|
||||
"mdi:harddisk",
|
||||
None,
|
||||
PERCENTAGE,
|
||||
True,
|
||||
@ -252,10 +259,91 @@ class BridgeFilesystemSensor(BridgeSensor):
|
||||
}
|
||||
|
||||
|
||||
class BridgeMemoryFreeSensor(BridgeSensor):
|
||||
"""Defines a memory free sensor."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge) -> None:
|
||||
"""Initialize System Bridge sensor."""
|
||||
super().__init__(
|
||||
coordinator,
|
||||
bridge,
|
||||
"memory_free",
|
||||
"Memory Free",
|
||||
"mdi:memory",
|
||||
None,
|
||||
DATA_GIGABYTES,
|
||||
True,
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> float | None:
|
||||
"""Return the state of the sensor."""
|
||||
bridge: Bridge = self.coordinator.data
|
||||
return (
|
||||
round(bridge.memory.free / 1000 ** 3, 2)
|
||||
if bridge.memory.free is not None
|
||||
else None
|
||||
)
|
||||
|
||||
|
||||
class BridgeMemoryUsedSensor(BridgeSensor):
|
||||
"""Defines a memory used sensor."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge) -> None:
|
||||
"""Initialize System Bridge sensor."""
|
||||
super().__init__(
|
||||
coordinator,
|
||||
bridge,
|
||||
"memory_used",
|
||||
"Memory Used",
|
||||
"mdi:memory",
|
||||
None,
|
||||
DATA_GIGABYTES,
|
||||
False,
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
"""Return the state of the sensor."""
|
||||
bridge: Bridge = self.coordinator.data
|
||||
return (
|
||||
round(bridge.memory.used / 1000 ** 3, 2)
|
||||
if bridge.memory.used is not None
|
||||
else None
|
||||
)
|
||||
|
||||
|
||||
class BridgeMemoryUsedPercentageSensor(BridgeSensor):
|
||||
"""Defines a memory used percentage sensor."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge) -> None:
|
||||
"""Initialize System Bridge sensor."""
|
||||
super().__init__(
|
||||
coordinator,
|
||||
bridge,
|
||||
"memory_used_percentage",
|
||||
"Memory Used %",
|
||||
"mdi:memory",
|
||||
None,
|
||||
PERCENTAGE,
|
||||
True,
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
"""Return the state of the sensor."""
|
||||
bridge: Bridge = self.coordinator.data
|
||||
return (
|
||||
round((bridge.memory.used / bridge.memory.total) * 100, 2)
|
||||
if bridge.memory.used is not None and bridge.memory.total is not None
|
||||
else None
|
||||
)
|
||||
|
||||
|
||||
class BridgeKernelSensor(BridgeSensor):
|
||||
"""Defines a kernel sensor."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge):
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge) -> None:
|
||||
"""Initialize System Bridge sensor."""
|
||||
super().__init__(
|
||||
coordinator,
|
||||
@ -278,7 +366,7 @@ class BridgeKernelSensor(BridgeSensor):
|
||||
class BridgeOsSensor(BridgeSensor):
|
||||
"""Defines an OS sensor."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge):
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge) -> None:
|
||||
"""Initialize System Bridge sensor."""
|
||||
super().__init__(
|
||||
coordinator,
|
||||
@ -301,7 +389,7 @@ class BridgeOsSensor(BridgeSensor):
|
||||
class BridgeProcessesLoadSensor(BridgeSensor):
|
||||
"""Defines a Processes Load sensor."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge):
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge) -> None:
|
||||
"""Initialize System Bridge sensor."""
|
||||
super().__init__(
|
||||
coordinator,
|
||||
@ -315,7 +403,7 @@ class BridgeProcessesLoadSensor(BridgeSensor):
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> float:
|
||||
def state(self) -> float | None:
|
||||
"""Return the state of the sensor."""
|
||||
bridge: Bridge = self.coordinator.data
|
||||
return (
|
||||
@ -338,3 +426,26 @@ class BridgeProcessesLoadSensor(BridgeSensor):
|
||||
if bridge.processes.load.currentLoadIdle is not None:
|
||||
attrs[ATTR_LOAD_IDLE] = round(bridge.processes.load.currentLoadIdle, 2)
|
||||
return attrs
|
||||
|
||||
|
||||
class BridgeBiosVersionSensor(BridgeSensor):
|
||||
"""Defines a bios version sensor."""
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, bridge: Bridge) -> None:
|
||||
"""Initialize System Bridge sensor."""
|
||||
super().__init__(
|
||||
coordinator,
|
||||
bridge,
|
||||
"bios_version",
|
||||
"BIOS Version",
|
||||
"mdi:chip",
|
||||
None,
|
||||
None,
|
||||
False,
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
"""Return the state of the sensor."""
|
||||
bridge: Bridge = self.coordinator.data
|
||||
return bridge.system.bios.version
|
||||
|
@ -2193,7 +2193,7 @@ synology-srm==0.2.0
|
||||
synologydsm-api==1.0.2
|
||||
|
||||
# homeassistant.components.system_bridge
|
||||
systembridge==1.1.3
|
||||
systembridge==1.1.5
|
||||
|
||||
# homeassistant.components.tahoma
|
||||
tahoma-api==0.0.16
|
||||
|
@ -1180,7 +1180,7 @@ surepy==0.6.0
|
||||
synologydsm-api==1.0.2
|
||||
|
||||
# homeassistant.components.system_bridge
|
||||
systembridge==1.1.3
|
||||
systembridge==1.1.5
|
||||
|
||||
# homeassistant.components.tellduslive
|
||||
tellduslive==0.10.11
|
||||
|
Loading…
x
Reference in New Issue
Block a user