Skip to content

Commit

Permalink
Fix gpu access
Browse files Browse the repository at this point in the history
  • Loading branch information
NickM-27 committed Nov 28, 2022
1 parent 47a6281 commit d22e8cd
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions custom_components/frigate/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def async_setup_entry(
elif key == "detectors":
for name in value.keys():
entities.append(DetectorSpeedSensor(coordinator, entry, name))
elif key == "gpus":
elif key == "gpu_usages":
for name in value.keys():
entities.append(GpuLoadSensor(coordinator, entry, name))
elif key == "service":
Expand Down Expand Up @@ -243,16 +243,17 @@ def __init__(
gpu_name: str,
) -> None:
"""Construct a GpuLoadSensor."""
self._gpu_name = gpu_name
self._attr_name = f"{get_friendly_name(self._gpu_name)} gpu load"
FrigateEntity.__init__(self, config_entry)
CoordinatorEntity.__init__(self, coordinator)
self._gpu_name = gpu_name
self._attr_entity_registry_enabled_default = False

@property
def unique_id(self) -> str:
"""Return a unique ID to use for this entity."""
return get_frigate_entity_unique_id(
self._config_entry.entry_id, "sensor_gpu_load", self._detector_name
self._config_entry.entry_id, "gpu_load", self._gpu_name
)

@property
Expand All @@ -266,17 +267,12 @@ def device_info(self) -> DeviceInfo:
"manufacturer": NAME,
}

@property
def name(self) -> str:
"""Return the name of the sensor."""
return f"{get_friendly_name(self._detector_name)} gpu load"

@property
def state(self) -> float | None:
"""Return the state of the sensor."""
if self.coordinator.data:
data = (
self.coordinator.data.get("gpus", {})
self.coordinator.data.get("gpu_usages", {})
.get(self._gpu_name, {})
.get("gpu_usage")
)
Expand Down

0 comments on commit d22e8cd

Please sign in to comment.