Skip to content

Commit 7a8edae

Browse files
Merge pull request #146 from PiotrMachowski/dev
v2.5.1
2 parents 9ce81d7 + f641209 commit 7a8edae

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

custom_components/tauron_amiplus/config_flow.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,6 @@ def get_schema_init(user_input=None):
181181
default=user_input.get(CONF_USERNAME, vol.UNDEFINED)): str,
182182
vol.Required(CONF_PASSWORD,
183183
default=user_input.get(CONF_PASSWORD, vol.UNDEFINED)): str,
184-
vol.Required(CONF_SHOW_GENERATION,
185-
default=False
186-
): bool,
187184
})
188185
return data_schema
189186

custom_components/tauron_amiplus/connector.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __init__(self, username, password, meter_id, show_generation=False, show_12_
106106
self.show_configurable = show_configurable
107107
self.show_configurable_date = show_configurable_date
108108
self.session = None
109-
self._cache = DailyDataCache()
109+
self._cache = DailyDataCache(meter_id)
110110

111111
def get_raw_data(self) -> TauronAmiplusRawData:
112112
data = TauronAmiplusRawData()
@@ -404,10 +404,12 @@ def add_all_data(data: dict, date):
404404

405405

406406
class DailyDataCache:
407-
def __init__(self):
407+
408+
def __init__(self, meter_id):
408409
self._consumption_data = dict()
409410
self._generation_data = dict()
410411
self._max_date = datetime.datetime.now() + datetime.timedelta(days=1)
412+
self._meter_id = meter_id
411413

412414
def __contains__(self, item: Tuple[str, bool]):
413415
date_str, generation = item
@@ -442,7 +444,7 @@ def delete_older_than(self, date: datetime.datetime):
442444

443445
def delete_day(self, date: datetime.datetime):
444446
date_str = self._format_date(date)
445-
_LOGGER.debug(f"Deleting data from cache for day: {date_str}")
447+
self.log(f"Deleting data from cache for day: {date_str}")
446448
if date_str in self._generation_data:
447449
self._generation_data.pop(date_str)
448450
if date_str in self._consumption_data:
@@ -451,3 +453,6 @@ def delete_day(self, date: datetime.datetime):
451453
@staticmethod
452454
def _format_date(date):
453455
return date.strftime("%Y-%m-%d")
456+
457+
def log(self, msg):
458+
_LOGGER.debug(f"[{self._meter_id}]: {msg}")

custom_components/tauron_amiplus/coordinator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class TauronAmiplusUpdateCoordinator(DataUpdateCoordinator[TauronAmiplusRawData]
1616
def __init__(self, hass: HomeAssistant, username, password, meter_id, show_generation=False, show_12_months=False,
1717
show_balanced=False, show_balanced_year=False, show_configurable=False, show_configurable_date=None,
1818
store_statistics=False):
19-
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=DEFAULT_UPDATE_INTERVAL)
19+
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=DEFAULT_UPDATE_INTERVAL,
20+
update_method=self.update_method)
2021
self.connector = TauronAmiplusConnector(username, password, meter_id, show_generation, show_12_months,
2122
show_balanced, show_balanced_year, show_configurable,
2223
show_configurable_date)
@@ -28,7 +29,7 @@ def __init__(self, hass: HomeAssistant, username, password, meter_id, show_gener
2829
self.show_configurable_date = show_configurable_date
2930
self.store_statistics = store_statistics
3031

31-
async def _async_update_data(self) -> TauronAmiplusRawData:
32+
async def update_method(self) -> TauronAmiplusRawData:
3233
self.log("Starting data update")
3334
data = await self.hass.async_add_executor_job(self._update)
3435
self.log("Downloaded all data")

custom_components/tauron_amiplus/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
"iot_class": "cloud_polling",
99
"issue_tracker": "https://github.com/PiotrMachowski/Home-Assistant-custom-components-Tauron-AMIplus/issues",
1010
"requirements": ["requests"],
11-
"version": "v2.5.0"
11+
"version": "v2.5.1"
1212
}

custom_components/tauron_amiplus/sensor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities):
9797
show_configurable=show_configurable,
9898
show_configurable_date=show_configurable_date,
9999
store_statistics=store_statistics)
100+
await coordinator.async_request_refresh()
100101
for sensor_type, sensor_type_config in sensor_types.items():
101102
sensors.append(
102103
TauronAmiplusConfigFlowSensor(
@@ -161,6 +162,7 @@ def state_class(self):
161162
return self._state_class
162163

163164
def _handle_coordinator_update(self) -> None:
165+
self.log(f"Updating data for entry: {self._sensor_type}")
164166
data: TauronAmiplusRawData = self.coordinator.data
165167
if not self.available or data is None:
166168
return
@@ -271,6 +273,9 @@ def unique_id(self):
271273
"""Return a unique ID."""
272274
return f"tauron-yaml-{self._meter_id}-{self._sensor_type.lower()}"
273275

276+
def log(self, msg):
277+
_LOGGER.debug(f"[{self._meter_id}]: {msg}")
278+
274279

275280
class TauronAmiplusConfigFlowSensor(TauronAmiplusSensor):
276281

0 commit comments

Comments
 (0)