From 060712148faaf057d32b0aacd2ed608f6833fbe2 Mon Sep 17 00:00:00 2001 From: tschoerk Date: Thu, 31 Oct 2024 13:54:30 +0100 Subject: [PATCH] Fixed having wrong zaehlpunkt with multi contracts When adding or updating a sensor, the zaehlpunkt is checked with the get_zaehlpunkt function. The problem was that the variable for the array, which has the zaehlpunkt details in them, had the same name as the zaehlpunkt itself. So when having multiple contracts/customerIds, the correct zaehlpunkt was overwritten by the zaehlpunkt details, which is now an empty array. All API requests were then done with an empty array and threw errors all around. --- custom_components/wnsm/api/client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_components/wnsm/api/client.py b/custom_components/wnsm/api/client.py index fc24a6e..c2fda80 100644 --- a/custom_components/wnsm/api/client.py +++ b/custom_components/wnsm/api/client.py @@ -241,10 +241,10 @@ def get_zaehlpunkt(self, zaehlpunkt: str = None) -> tuple[str, str, str]: else: customer_id = zp = anlagetype = None for contract in contracts: - zp = [z for z in contract["zaehlpunkte"] if z["zaehlpunktnummer"] == zaehlpunkt] - if len(zp) > 0: - anlagetype = zp[0]["anlage"]["typ"] - zp = zp[0]["zaehlpunktnummer"] + zp_details = [z for z in contract["zaehlpunkte"] if z["zaehlpunktnummer"] == zaehlpunkt] + if len(zp_details) > 0: + anlagetype = zp_details[0]["anlage"]["typ"] + zp = zp_details[0]["zaehlpunktnummer"] customer_id = contract["geschaeftspartner"] return customer_id, zp, const.AnlageType.from_str(anlagetype)