Skip to content

Commit

Permalink
enhancement(AnlageType): Add AnlageType NACHSTROM
Browse files Browse the repository at this point in the history
Add more context to NotImplementedError
Fixes #279
  • Loading branch information
DarwinsBuddy committed Nov 24, 2024
1 parent 92d4eb2 commit 119ba21
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
4 changes: 2 additions & 2 deletions custom_components/wnsm/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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:
Expand Down
19 changes: 8 additions & 11 deletions custom_components/wnsm/api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
16 changes: 8 additions & 8 deletions tests/it/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/it/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 119ba21

Please sign in to comment.