Skip to content

Commit 8aba8bd

Browse files
committed
filter entities and fix ids
1 parent 672873f commit 8aba8bd

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

custom_components/fronius_local/api.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from homeassistant.helpers import httpx_client
99

1010
from . import auth
11+
from . import const as fl
1112

1213
if TYPE_CHECKING:
1314
from homeassistant.core import HomeAssistant
@@ -23,6 +24,18 @@ def meta(item: str) -> str:
2324
return "_" + item + "_meta"
2425

2526

27+
def get_type(data: dict, key: str) -> Platform:
28+
"""Get type of sensor."""
29+
if key in fl.FILTER:
30+
return Platform.SENSOR
31+
if (
32+
data[meta(key)]["writePermission"]["RoleCustomer"]
33+
and data[meta(key)]["displayType"] == "Integer"
34+
):
35+
return Platform.NUMBER
36+
return Platform.SENSOR
37+
38+
2639
class FroniusApiClient:
2740
"""Fronius auth class."""
2841

@@ -67,10 +80,7 @@ async def async_get_data(self) -> dict:
6780
battery = {
6881
"conf_batteries_" + k: {
6982
"value": v,
70-
"type": Platform.NUMBER
71-
if battery[meta(k)]["writePermission"]["RoleCustomer"]
72-
and battery[meta(k)]["displayType"] == "Integer"
73-
else Platform.SENSOR,
83+
"type": get_type(battery, k),
7484
"name": (await self.async_get_translation(self.hass.config.language))[
7585
"BATTERIES"
7686
].get(k)

custom_components/fronius_local/const.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@
1010
LOGGER: logging.Logger = logging.getLogger(DOMAIN)
1111

1212
UPDATE_INTERVAL = 9
13+
14+
FILTER = [
15+
"PV_PEAK_POWER",
16+
"supportSoc",
17+
"supportSocHysteresisMin",
18+
"supportSocHysteresisEnergy",
19+
]

custom_components/fronius_local/number.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ def __init__(
4949
"""Initialize the sensor class."""
5050
super().__init__(coordinator, unique_id)
5151
self.entity_description = entity_description
52+
self.entity_id = "number." + unique_id
53+
54+
self.extra_state_attributes = {"id": self.data()["id"]}
5255

5356
self.mode = "box"
5457
self.native_unit_of_measurement = self.data()["unit"]

custom_components/fronius_local/sensor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def __init__(
5454
"""Initialize the sensor class."""
5555
super().__init__(coordinator, unique_id)
5656
self.entity_description = entity_description
57+
self.entity_id = "sensor." + unique_id
58+
59+
self.extra_state_attributes = {"id": self.data()["id"]}
5760

5861
if self.data()["unit"] is not None:
5962
self.native_unit_of_measurement = self.data()["unit"]

0 commit comments

Comments
 (0)