From a953cae93d79fe54825547f62c9341c175f3eb7a Mon Sep 17 00:00:00 2001 From: magnuselden Date: Sat, 9 Sep 2023 21:02:19 +0200 Subject: [PATCH] #24 --- custom_components/peaqnext/__init__.py | 5 +++-- custom_components/peaqnext/manifest.json | 3 ++- custom_components/peaqnext/sensors/next_sensor.py | 2 +- custom_components/peaqnext/service/hub.py | 10 +++++----- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/custom_components/peaqnext/__init__.py b/custom_components/peaqnext/__init__.py index 8cd7622..55ab74f 100644 --- a/custom_components/peaqnext/__init__.py +++ b/custom_components/peaqnext/__init__.py @@ -13,7 +13,8 @@ from custom_components.peaqnext.service.models.consumption_type import ConsumptionType from custom_components.peaqnext.service.models.sensor_model import NextSensor from .const import (CONF_CALCULATE_BY, CONF_CUSTOM_CONSUMPTION_PATTERN, CONF_DEDUCT_PRICE, CONF_UPDATE_BY, DOMAIN, PLATFORMS, HUB, CONF_NONHOURS_END, CONF_CONSUMPTION_TYPE, CONF_NAME, CONF_NONHOURS_START, CONF_SENSORS, CONF_TOTAL_CONSUMPTION_IN_KWH, CONF_TOTAL_DURATION_IN_MINUTES, CONF_CLOSEST_CHEAP) - +from datetime import datetime +from uuid import uuid4 _LOGGER = logging.getLogger(__name__) @@ -21,7 +22,7 @@ async def async_setup_entry(hass: HomeAssistant, conf: ConfigEntry) -> bool: hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][conf.entry_id] = conf.data - hub = Hub(hass) + hub = Hub(hass, hub_id=datetime.now().strftime('%Y%m-%d%H-%M%S-') + str(uuid4())) hass.data[DOMAIN][HUB] = hub internal_sensors = await async_create_internal_sensors(conf) await hub.async_setup(internal_sensors) diff --git a/custom_components/peaqnext/manifest.json b/custom_components/peaqnext/manifest.json index 29208da..5a352e2 100644 --- a/custom_components/peaqnext/manifest.json +++ b/custom_components/peaqnext/manifest.json @@ -3,6 +3,7 @@ "name": "peaqnext, utility sensors", "after_dependencies": [ "nordpool", + "energidataservice", "peaqev" ], "codeowners": [ @@ -13,5 +14,5 @@ "integration_type": "hub", "iot_class": "calculated", "issue_tracker": "https://github.com/elden1337/hass-peaqnext/issues", - "version": "0.5.2" + "version": "0.5.3" } \ No newline at end of file diff --git a/custom_components/peaqnext/sensors/next_sensor.py b/custom_components/peaqnext/sensors/next_sensor.py index bae1a9f..2c979f9 100644 --- a/custom_components/peaqnext/sensors/next_sensor.py +++ b/custom_components/peaqnext/sensors/next_sensor.py @@ -94,7 +94,7 @@ def extra_state_attributes(self) -> dict: def device_info(self): return { "identifiers": {(DOMAIN, self.hub.hub_id)}, - "name": f"{DOMAIN} {HUB}", + "name": f"{DOMAIN} {HUB} ({self.hub.hub_id})", "sw_version": 1, "model": "Normal", "manufacturer": "Peaq systems", diff --git a/custom_components/peaqnext/service/hub.py b/custom_components/peaqnext/service/hub.py index d4faff9..673f0de 100644 --- a/custom_components/peaqnext/service/hub.py +++ b/custom_components/peaqnext/service/hub.py @@ -13,16 +13,16 @@ class Hub: - hub_id = 33512 hubname = "PeaqNext" - sensors_dict: dict[str:NextSensor] = {} - sensors: list[NextSensor] = [] - - def __init__(self, hass, test:bool = False) -> Any: + + def __init__(self, hass, hub_id, test:bool = False) -> Any: + self.hub_id = hub_id if not test: self.state_machine: HomeAssistant = hass self._current_minute: int = None self.prices: tuple[list,list] = ([], []) + self.sensors_dict: dict[str:NextSensor] = {} + self.sensors: list[NextSensor] = [] self.spotprice: ISpotPrice = SpotPriceFactory.create(self, test) self.latest_spotprice_update = 0 if not test: