Adjust Plenticore sensor initialisation (#78869)
parent
988e8bfe7b
commit
063074acf5
|
@ -26,7 +26,7 @@ from homeassistant.const import (
|
||||||
POWER_WATT,
|
POWER_WATT,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
@ -836,9 +836,6 @@ async def async_setup_entry(
|
||||||
for description in SENSOR_PROCESS_DATA:
|
for description in SENSOR_PROCESS_DATA:
|
||||||
module_id = description.module_id
|
module_id = description.module_id
|
||||||
data_id = description.key
|
data_id = description.key
|
||||||
name = description.name
|
|
||||||
sensor_data = description.properties
|
|
||||||
fmt = description.formatter
|
|
||||||
if (
|
if (
|
||||||
module_id not in available_process_data
|
module_id not in available_process_data
|
||||||
or data_id not in available_process_data[module_id]
|
or data_id not in available_process_data[module_id]
|
||||||
|
@ -851,15 +848,10 @@ async def async_setup_entry(
|
||||||
entities.append(
|
entities.append(
|
||||||
PlenticoreDataSensor(
|
PlenticoreDataSensor(
|
||||||
process_data_update_coordinator,
|
process_data_update_coordinator,
|
||||||
|
description,
|
||||||
entry.entry_id,
|
entry.entry_id,
|
||||||
entry.title,
|
entry.title,
|
||||||
module_id,
|
|
||||||
data_id,
|
|
||||||
name,
|
|
||||||
sensor_data,
|
|
||||||
PlenticoreDataFormatter.get_method(fmt),
|
|
||||||
plenticore.device_info,
|
plenticore.device_info,
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -869,34 +861,32 @@ async def async_setup_entry(
|
||||||
class PlenticoreDataSensor(CoordinatorEntity, SensorEntity):
|
class PlenticoreDataSensor(CoordinatorEntity, SensorEntity):
|
||||||
"""Representation of a Plenticore data Sensor."""
|
"""Representation of a Plenticore data Sensor."""
|
||||||
|
|
||||||
|
entity_description: PlenticoreSensorEntityDescription
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator,
|
coordinator: ProcessDataUpdateCoordinator,
|
||||||
|
description: PlenticoreSensorEntityDescription,
|
||||||
entry_id: str,
|
entry_id: str,
|
||||||
platform_name: str,
|
platform_name: str,
|
||||||
module_id: str,
|
|
||||||
data_id: str,
|
|
||||||
sensor_name: str | None,
|
|
||||||
sensor_data: dict[str, Any],
|
|
||||||
formatter: Callable[[str], Any],
|
|
||||||
device_info: DeviceInfo,
|
device_info: DeviceInfo,
|
||||||
entity_category: EntityCategory | None,
|
) -> None:
|
||||||
):
|
|
||||||
"""Create a new Sensor Entity for Plenticore process data."""
|
"""Create a new Sensor Entity for Plenticore process data."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
|
self.entity_description = description
|
||||||
self.entry_id = entry_id
|
self.entry_id = entry_id
|
||||||
self.platform_name = platform_name
|
self.platform_name = platform_name
|
||||||
self.module_id = module_id
|
self.module_id = description.module_id
|
||||||
self.data_id = data_id
|
self.data_id = description.key
|
||||||
|
|
||||||
self._sensor_name = sensor_name
|
self._sensor_name = description.name
|
||||||
self._sensor_data = sensor_data
|
self._sensor_data = description.properties
|
||||||
self._formatter = formatter
|
self._formatter: Callable[[str], Any] = PlenticoreDataFormatter.get_method(
|
||||||
|
description.formatter
|
||||||
|
)
|
||||||
|
|
||||||
self._device_info = device_info
|
self._device_info = device_info
|
||||||
|
|
||||||
self._attr_entity_category = entity_category
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
"""Return if entity is available."""
|
"""Return if entity is available."""
|
||||||
|
|
Loading…
Reference in New Issue