mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-10-11 11:56:17 +00:00
Some checks failed
docker-build / platform-excludes (push) Has been cancelled
pre-commit / pre-commit (push) Has been cancelled
Run Pytest on Pull Request / test (push) Has been cancelled
docker-build / build (push) Has been cancelled
docker-build / merge (push) Has been cancelled
Close stale pull requests/issues / Find Stale issues and PRs (push) Has been cancelled
* Fix logging configuration issues that made logging stop operation. Switch to Loguru logging (from Python logging). Enable console and file logging with different log levels. Add logging documentation. * Fix logging configuration and EOS configuration out of sync. Added tracking support for nested value updates of Pydantic models. This used to update the logging configuration when the EOS configurationm for logging is changed. Should keep logging config and EOS config in sync as long as all changes to the EOS logging configuration are done by set_nested_value(), which is the case for the REST API. * Fix energy management task looping endlessly after the second update when trying to update the last_update datetime. * Fix get_nested_value() to correctly take values from the dicts in a Pydantic model instance. * Fix usage of model classes instead of model instances in nested value access when evaluation the value type that is associated to each key. * Fix illegal json format in prediction documentation for PVForecastAkkudoktor provider. * Fix documentation qirks and add EOS Connect to integrations. * Support deprecated fields in configuration in documentation generation and EOSdash. * Enhance EOSdash demo to show BrightSky humidity data (that is often missing) * Update documentation reference to German EOS installation videos. Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
80 lines
3.0 KiB
Python
80 lines
3.0 KiB
Python
from typing import Optional
|
|
|
|
import numpy as np
|
|
from pydantic import Field
|
|
|
|
from akkudoktoreos.devices.devicesabc import DeviceBase, DeviceParameters
|
|
|
|
|
|
class HomeApplianceParameters(DeviceParameters):
|
|
"""Home Appliance Device Simulation Configuration."""
|
|
|
|
device_id: str = Field(description="ID of home appliance", examples=["dishwasher"])
|
|
consumption_wh: int = Field(
|
|
gt=0,
|
|
description="An integer representing the energy consumption of a household device in watt-hours.",
|
|
examples=[2000],
|
|
)
|
|
duration_h: int = Field(
|
|
gt=0,
|
|
description="An integer representing the usage duration of a household device in hours.",
|
|
examples=[3],
|
|
)
|
|
|
|
|
|
class HomeAppliance(DeviceBase):
|
|
def __init__(
|
|
self,
|
|
parameters: Optional[HomeApplianceParameters] = None,
|
|
):
|
|
self.parameters: Optional[HomeApplianceParameters] = None
|
|
super().__init__(parameters)
|
|
|
|
def _setup(self) -> None:
|
|
if self.parameters is None:
|
|
raise ValueError(f"Parameters not set: {self.parameters}")
|
|
self.load_curve = np.zeros(self.hours) # Initialize the load curve with zeros
|
|
self.duration_h = self.parameters.duration_h
|
|
self.consumption_wh = self.parameters.consumption_wh
|
|
|
|
def set_starting_time(self, start_hour: int, global_start_hour: int = 0) -> None:
|
|
"""Sets the start time of the device and generates the corresponding load curve.
|
|
|
|
:param start_hour: The hour at which the device should start.
|
|
"""
|
|
self.reset_load_curve()
|
|
# Check if the duration of use is within the available time frame
|
|
if start_hour + self.duration_h > self.hours:
|
|
raise ValueError("The duration of use exceeds the available time frame.")
|
|
if start_hour < global_start_hour:
|
|
raise ValueError("The start time is earlier than the available time frame.")
|
|
|
|
# Calculate power per hour based on total consumption and duration
|
|
power_per_hour = self.consumption_wh / self.duration_h # Convert to watt-hours
|
|
|
|
# Set the power for the duration of use in the load curve array
|
|
self.load_curve[start_hour : start_hour + self.duration_h] = power_per_hour
|
|
|
|
def reset_load_curve(self) -> None:
|
|
"""Resets the load curve."""
|
|
self.load_curve = np.zeros(self.hours)
|
|
|
|
def get_load_curve(self) -> np.ndarray:
|
|
"""Returns the current load curve."""
|
|
return self.load_curve
|
|
|
|
def get_load_for_hour(self, hour: int) -> float:
|
|
"""Returns the load for a specific hour.
|
|
|
|
:param hour: The hour for which the load is queried.
|
|
:return: The load in watts for the specified hour.
|
|
"""
|
|
if hour < 0 or hour >= self.hours:
|
|
raise ValueError("The specified hour is outside the available time frame.")
|
|
|
|
return self.load_curve[hour]
|
|
|
|
def get_latest_starting_point(self) -> int:
|
|
"""Returns the latest possible start time at which the device can still run completely."""
|
|
return self.hours - self.duration_h
|