diff --git a/custom_components/wnsm/api/client.py b/custom_components/wnsm/api/client.py index 8d70dbd..010203c 100644 --- a/custom_components/wnsm/api/client.py +++ b/custom_components/wnsm/api/client.py @@ -247,7 +247,7 @@ def get_zaehlpunkt(self, zaehlpunkt: str = None) -> tuple[str, str, str]: anlagetype = zp_details[0]["anlage"]["typ"] zp = zp_details[0]["zaehlpunktnummer"] customer_id = contract["geschaeftspartner"] - return customer_id, zp, const.AnlageType.from_str(anlagetype) + return customer_id, zp, const.AnlagenType.from_str(anlagetype) def zaehlpunkte(self): """Returns zaehlpunkte for currently logged in user.""" @@ -509,7 +509,7 @@ def bewegungsdaten( """ customer_id, zaehlpunkt, anlagetype = self.get_zaehlpunkt(zaehlpunktnummer) - if anlagetype == const.AnlageType.FEEDING: + if anlagetype == const.AnlagenType.FEEDING: if valuetype == const.ValueType.DAY: rolle = const.RoleType.DAILY_FEEDING.value else: diff --git a/custom_components/wnsm/api/constants.py b/custom_components/wnsm/api/constants.py index 84e40dd..bdc40a2 100644 --- a/custom_components/wnsm/api/constants.py +++ b/custom_components/wnsm/api/constants.py @@ -53,23 +53,20 @@ def from_str(label): else: raise NotImplementedError -class AnlageType(enum.Enum): +class AnlagenType(enum.Enum): """Possible types for the zaehlpunkte""" CONSUMING = "TAGSTROM" #: Zaehlpunkt is consuming ("normal" power connection) FEEDING = "BEZUG" #: Zaehlpunkt is feeding (produced power from PV, etc.) @staticmethod def from_str(label): - if label in ('TAGSTROM', 'tagstrom'): - return AnlageType.CONSUMING - elif label in ('WAERMEPUMPE', 'waermepumpe'): - return AnlageType.CONSUMING - elif label in ('STROM', 'strom'): - return AnlageType.CONSUMING - elif label in ('BEZUG', 'bezug'): - return AnlageType.FEEDING - else: - raise NotImplementedError + match label.upper(): + case 'TAGSTROM' | 'NACHTSTROM' | 'WAERMEPUMPE' | 'STROM': + return AnlagenType.CONSUMING + case 'BEZUG': + return AnlagenType.FEEDING + case _: + raise NotImplementedError(f"AnlageType {label} not implemented") class RoleType(enum.Enum): """Possible types for the roles of bewegungsdaten - depending on the settings set in smart meter portal""" diff --git a/tests/it/__init__.py b/tests/it/__init__.py index 3384b0e..0694462 100644 --- a/tests/it/__init__.py +++ b/tests/it/__init__.py @@ -18,7 +18,7 @@ myPath = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, myPath + '/../../custom_components') from wnsm import api # noqa: E402 -from wnsm.api.constants import ValueType, AnlageType, RoleType # noqa: E402 +from wnsm.api.constants import ValueType, AnlagenType, RoleType # noqa: E402 def _dt_string(datetime_string): @@ -326,18 +326,18 @@ def bewegungsdaten(count=24, timestamp=None, interval='h'): return [bewegungsdaten_value(timestamp, interval, i) for i in list(range(0,count))] -def bewegungsdaten_response(customer_id: str, zp: str, - granularity: ValueType = ValueType.QUARTER_HOUR, anlagetype: AnlageType = AnlageType.CONSUMING, +def bewegungsdaten_response(customer_id: str, zp: str, + granularity: ValueType = ValueType.QUARTER_HOUR, anlagetype: AnlagenType = AnlagenType.CONSUMING, wrong_zp: bool = False, values_count: int = 10): if (granularity == ValueType.QUARTER_HOUR): gran = "QH" - if(anlagetype == AnlageType.CONSUMING): + if(anlagetype == AnlagenType.CONSUMING): rolle = "V002" else: rolle = "E002" else: gran = "D" - if(anlagetype == AnlageType.CONSUMING): + if(anlagetype == AnlagenType.CONSUMING): rolle = "V001" else: rolle = "V002" @@ -559,10 +559,10 @@ def expect_history( ) @pytest.mark.usefixtures("requests_mock") -def expect_bewegungsdaten(requests_mock: Mocker, customer_id: str, zp: str, dateFrom: dt.datetime, dateTo: dt.datetime, - granularity:ValueType = ValueType.QUARTER_HOUR, anlagetype: AnlageType = AnlageType.CONSUMING, +def expect_bewegungsdaten(requests_mock: Mocker, customer_id: str, zp: str, dateFrom: dt.datetime, dateTo: dt.datetime, + granularity:ValueType = ValueType.QUARTER_HOUR, anlagetype: AnlagenType = AnlagenType.CONSUMING, wrong_zp: bool = False, values_count=10): - if anlagetype== AnlageType.FEEDING: + if anlagetype== AnlagenType.FEEDING: if granularity == ValueType.DAY: rolle = RoleType.DAILY_FEEDING.value else: diff --git a/tests/it/test_api.py b/tests/it/test_api.py index 1f6af83..6ab3f0e 100644 --- a/tests/it/test_api.py +++ b/tests/it/test_api.py @@ -371,7 +371,7 @@ def test_bewegungsdaten_quarterly_hour_feeding(requests_mock: Mocker): dateTo = dt.datetime(2023, 5, 1, 23, 59, 59, 999999) zpn = z["zaehlpunkte"][0]['zaehlpunktnummer'] expect_login(requests_mock) - expect_bewegungsdaten(requests_mock, z["geschaeftspartner"], zpn, dateFrom, dateTo, const.ValueType.QUARTER_HOUR, const.AnlageType.FEEDING, values_count=COUNT) + expect_bewegungsdaten(requests_mock, z["geschaeftspartner"], zpn, dateFrom, dateTo, const.ValueType.QUARTER_HOUR, const.AnlagenType.FEEDING, values_count=COUNT) expect_zaehlpunkte(requests_mock, [enabled(zaehlpunkt_feeding())]) hist = smartmeter().login().bewegungsdaten(None, dateFrom, dateTo) @@ -385,7 +385,7 @@ def test_bewegungsdaten_daily_feeding(requests_mock: Mocker): dateTo = dt.datetime(2023, 5, 1, 23, 59, 59, 999999) zpn = z["zaehlpunkte"][0]['zaehlpunktnummer'] expect_login(requests_mock) - expect_bewegungsdaten(requests_mock, z["geschaeftspartner"], zpn, dateFrom, dateTo, const.ValueType.DAY, const.AnlageType.FEEDING, values_count=COUNT) + expect_bewegungsdaten(requests_mock, z["geschaeftspartner"], zpn, dateFrom, dateTo, const.ValueType.DAY, const.AnlagenType.FEEDING, values_count=COUNT) expect_zaehlpunkte(requests_mock, [enabled(zaehlpunkt_feeding())]) hist = smartmeter().login().bewegungsdaten(None, dateFrom, dateTo, const.ValueType.DAY)