-
Notifications
You must be signed in to change notification settings - Fork 117
Kostal Piko Bat #3298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Kostal Piko Bat #3298
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #!/usr/bin/env python3 | ||
| import logging | ||
| from typing import Any, List, Tuple, TypedDict | ||
|
|
||
| from modules.common import req | ||
| from modules.common.abstract_device import AbstractBat | ||
| from modules.common.component_state import BatState | ||
| from modules.common.component_type import ComponentDescriptor | ||
| from modules.common.fault_state import ComponentInfo, FaultState | ||
| from modules.common.simcount import SimCounter | ||
| from modules.common.store import get_bat_value_store | ||
| from modules.devices.kostal.kostal_piko.config import KostalPikoBatSetup | ||
| from modules.common.utils.peak_filter import PeakFilter | ||
| from modules.common.component_type import ComponentType | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class KwargsDict(TypedDict): | ||
| device_id: int | ||
| ip_address: str | ||
|
|
||
|
|
||
| class KostalPikoBat(AbstractBat): | ||
| def __init__(self, component_config: KostalPikoBatSetup, **kwargs: Any) -> None: | ||
| self.component_config = component_config | ||
| self.kwargs: KwargsDict = kwargs | ||
|
|
||
| def initialize(self) -> None: | ||
| self.__device_id: int = self.kwargs['device_id'] | ||
| self.ip_address: str = self.kwargs['ip_address'] | ||
| self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="speicher") | ||
| self.store = get_bat_value_store(self.component_config.id) | ||
| self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config)) | ||
| self.peak_filter = PeakFilter(ComponentType.BAT, self.component_config.id, self.fault_state) | ||
|
|
||
| def get_values(self) -> Tuple[float, List[float]]: | ||
| # Bat Current, Bat Voltage, Bat SoC | ||
| params = (('dxsEntries', ['33556225', '33556226', '33556229']),) | ||
| resp = req.get_http_session().get('http://'+self.ip_address+'/api/dxs.json', | ||
| params=params, | ||
| timeout=3).json()["dxsEntries"] | ||
| power = float(resp[0]["value"]) * float(resp[1]["value"]) | ||
| soc = float(resp[2]["value"]) | ||
| return power, soc | ||
|
|
||
| def update(self): | ||
| power, soc = self.get_values() | ||
|
|
||
| self.peak_filter.check_values(power) | ||
| imported, exported = self.sim_counter.sim_count(power) | ||
| bat_state = BatState( | ||
| imported=imported, | ||
| exported=exported, | ||
| power=power, | ||
| soc=soc | ||
| ) | ||
| self.store.set(bat_state) | ||
|
Comment on lines
+37
to
+58
|
||
|
|
||
|
|
||
| component_descriptor = ComponentDescriptor(configuration_factory=KostalPikoBatSetup) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_valuesis annotated to returnTuple[float, List[float]], but it actually returns(power, soc)wheresocis afloat. This mismatch makes the API misleading and will be flagged by type checkers; adjust the return type (and related imports) to match the real return value.