Add support for logger info in fronius integration (#54795)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
b6a1153d42
commit
6d049c724c
3 changed files with 28 additions and 7 deletions
|
@ -2,7 +2,7 @@
|
||||||
"domain": "fronius",
|
"domain": "fronius",
|
||||||
"name": "Fronius",
|
"name": "Fronius",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/fronius",
|
"documentation": "https://www.home-assistant.io/integrations/fronius",
|
||||||
"requirements": ["pyfronius==0.5.5"],
|
"requirements": ["pyfronius==0.6.0"],
|
||||||
"codeowners": ["@nielstron"],
|
"codeowners": ["@nielstron"],
|
||||||
"iot_class": "local_polling"
|
"iot_class": "local_polling"
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
||||||
import copy
|
import copy
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from pyfronius import Fronius
|
from pyfronius import Fronius
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
@ -32,6 +33,7 @@ from homeassistant.const import (
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.event import async_track_time_interval
|
from homeassistant.helpers.event import async_track_time_interval
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -42,6 +44,7 @@ TYPE_INVERTER = "inverter"
|
||||||
TYPE_STORAGE = "storage"
|
TYPE_STORAGE = "storage"
|
||||||
TYPE_METER = "meter"
|
TYPE_METER = "meter"
|
||||||
TYPE_POWER_FLOW = "power_flow"
|
TYPE_POWER_FLOW = "power_flow"
|
||||||
|
TYPE_LOGGER_INFO = "logger_info"
|
||||||
SCOPE_DEVICE = "device"
|
SCOPE_DEVICE = "device"
|
||||||
SCOPE_SYSTEM = "system"
|
SCOPE_SYSTEM = "system"
|
||||||
|
|
||||||
|
@ -50,7 +53,13 @@ DEFAULT_DEVICE = 0
|
||||||
DEFAULT_INVERTER = 1
|
DEFAULT_INVERTER = 1
|
||||||
DEFAULT_SCAN_INTERVAL = timedelta(seconds=60)
|
DEFAULT_SCAN_INTERVAL = timedelta(seconds=60)
|
||||||
|
|
||||||
SENSOR_TYPES = [TYPE_INVERTER, TYPE_STORAGE, TYPE_METER, TYPE_POWER_FLOW]
|
SENSOR_TYPES = [
|
||||||
|
TYPE_INVERTER,
|
||||||
|
TYPE_STORAGE,
|
||||||
|
TYPE_METER,
|
||||||
|
TYPE_POWER_FLOW,
|
||||||
|
TYPE_LOGGER_INFO,
|
||||||
|
]
|
||||||
SCOPE_TYPES = [SCOPE_DEVICE, SCOPE_SYSTEM]
|
SCOPE_TYPES = [SCOPE_DEVICE, SCOPE_SYSTEM]
|
||||||
|
|
||||||
PREFIX_DEVICE_CLASS_MAPPING = [
|
PREFIX_DEVICE_CLASS_MAPPING = [
|
||||||
|
@ -138,6 +147,8 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||||
adapter_cls = FroniusMeterDevice
|
adapter_cls = FroniusMeterDevice
|
||||||
elif sensor_type == TYPE_POWER_FLOW:
|
elif sensor_type == TYPE_POWER_FLOW:
|
||||||
adapter_cls = FroniusPowerFlow
|
adapter_cls = FroniusPowerFlow
|
||||||
|
elif sensor_type == TYPE_LOGGER_INFO:
|
||||||
|
adapter_cls = FroniusLoggerInfo
|
||||||
else:
|
else:
|
||||||
adapter_cls = FroniusStorage
|
adapter_cls = FroniusStorage
|
||||||
|
|
||||||
|
@ -161,16 +172,18 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||||
class FroniusAdapter:
|
class FroniusAdapter:
|
||||||
"""The Fronius sensor fetching component."""
|
"""The Fronius sensor fetching component."""
|
||||||
|
|
||||||
def __init__(self, bridge, name, device, add_entities):
|
def __init__(
|
||||||
|
self, bridge: Fronius, name: str, device: int, add_entities: AddEntitiesCallback
|
||||||
|
) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self.bridge = bridge
|
self.bridge = bridge
|
||||||
self._name = name
|
self._name = name
|
||||||
self._device = device
|
self._device = device
|
||||||
self._fetched = {}
|
self._fetched: dict[str, Any] = {}
|
||||||
self._available = True
|
self._available = True
|
||||||
|
|
||||||
self.sensors = set()
|
self.sensors: set[str] = set()
|
||||||
self._registered_sensors = set()
|
self._registered_sensors: set[SensorEntity] = set()
|
||||||
self._add_entities = add_entities
|
self._add_entities = add_entities
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -289,6 +302,14 @@ class FroniusPowerFlow(FroniusAdapter):
|
||||||
return await self.bridge.current_power_flow()
|
return await self.bridge.current_power_flow()
|
||||||
|
|
||||||
|
|
||||||
|
class FroniusLoggerInfo(FroniusAdapter):
|
||||||
|
"""Adapter for the fronius power flow."""
|
||||||
|
|
||||||
|
async def _update(self):
|
||||||
|
"""Get the values for the current state."""
|
||||||
|
return await self.bridge.current_logger_info()
|
||||||
|
|
||||||
|
|
||||||
class FroniusTemplateSensor(SensorEntity):
|
class FroniusTemplateSensor(SensorEntity):
|
||||||
"""Sensor for the single values (e.g. pv power, ac power)."""
|
"""Sensor for the single values (e.g. pv power, ac power)."""
|
||||||
|
|
||||||
|
|
|
@ -1472,7 +1472,7 @@ pyfreedompro==1.1.0
|
||||||
pyfritzhome==0.6.2
|
pyfritzhome==0.6.2
|
||||||
|
|
||||||
# homeassistant.components.fronius
|
# homeassistant.components.fronius
|
||||||
pyfronius==0.5.5
|
pyfronius==0.6.0
|
||||||
|
|
||||||
# homeassistant.components.ifttt
|
# homeassistant.components.ifttt
|
||||||
pyfttt==0.3
|
pyfttt==0.3
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue