* Add Amber Electric integration * Linting * Fixing some type hinting * Adding docstrings * Removing files that shouldn't have been changed * Splitting out test helpers * Testing the price sensor * Testing Controlled load and feed in channels * Refactoring mocks * switching state for native_value and unit_of_measurement for native_unit_of_measurement * Fixing docstrings * Fixing requiremennts_all.txt * isort fixes * Fixing pylint errors * Omitting __init__.py from test coverage * Add missing config_flow tests * Adding more sensor tests * Applying suggested changes to __init.py__ * Refactor coordinator to return the data object with all of the relevent data already setup * Another coordinator refactor - Better use the dictionary for when we build the sensors * Removing first function * Refactoring sensor files to use entity descriptions, remove factory * Rounding renewable percentage, return icons correctly * Cleaning up translation strings * Fixing relative path, removing TODO * Coordintator tests now accept new (more accurate) fixtures * Using a description placeholder * Putting missing translations strings back in * tighten up the no site error logic - self._site_id should never be None at the point of loading async_step_site * Removing DEVICE_CLASS, replacing the units with AUD/kWh * Settings _attr_unique_id * Removing icon function (it's already the default) * Apply suggestions from code review Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Adding strings.json * Tighter wrapping for try/except * Generating translations * Removing update_method - not needed as it's being overriden * Apply suggestions from code review Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Fixing tests * Add missing description placeholder * Fix warning * changing name from update to update_data to match async_update_data * renaming [async_]update_data => [async_]update_price_data to avoid confusion * Creating too man renewable sensors * Override update method * Coordinator tests use _async_update_data * Using $/kWh as the units * Using isinstance instead of __class__ test. Removing a zero len check * Asserting self._sites in second step * Linting * Remove useless tests Co-authored-by: jan iversen <jancasacondor@gmail.com> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
121 lines
3.7 KiB
Python
121 lines
3.7 KiB
Python
"""Some common test functions for testing Amber components."""
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
from amberelectric.model.actual_interval import ActualInterval
|
|
from amberelectric.model.channel import ChannelType
|
|
from amberelectric.model.current_interval import CurrentInterval
|
|
from amberelectric.model.forecast_interval import ForecastInterval
|
|
from amberelectric.model.interval import SpikeStatus
|
|
from dateutil import parser
|
|
|
|
|
|
def generate_actual_interval(
|
|
channel_type: ChannelType, end_time: datetime
|
|
) -> ActualInterval:
|
|
"""Generate a mock actual interval."""
|
|
start_time = end_time - timedelta(minutes=30)
|
|
return ActualInterval(
|
|
duration=30,
|
|
spot_per_kwh=1.0,
|
|
per_kwh=8.0,
|
|
date=start_time.date(),
|
|
nem_time=end_time,
|
|
start_time=start_time,
|
|
end_time=end_time,
|
|
renewables=50,
|
|
channel_type=channel_type.value,
|
|
spike_status=SpikeStatus.NO_SPIKE.value,
|
|
)
|
|
|
|
|
|
def generate_current_interval(
|
|
channel_type: ChannelType, end_time: datetime
|
|
) -> CurrentInterval:
|
|
"""Generate a mock current price."""
|
|
start_time = end_time - timedelta(minutes=30)
|
|
return CurrentInterval(
|
|
duration=30,
|
|
spot_per_kwh=1.0,
|
|
per_kwh=8.0,
|
|
date=start_time.date(),
|
|
nem_time=end_time,
|
|
start_time=start_time,
|
|
end_time=end_time,
|
|
renewables=50.6,
|
|
channel_type=channel_type.value,
|
|
spike_status=SpikeStatus.NO_SPIKE.value,
|
|
estimate=True,
|
|
)
|
|
|
|
|
|
def generate_forecast_interval(
|
|
channel_type: ChannelType, end_time: datetime
|
|
) -> ForecastInterval:
|
|
"""Generate a mock forecast interval."""
|
|
start_time = end_time - timedelta(minutes=30)
|
|
return ForecastInterval(
|
|
duration=30,
|
|
spot_per_kwh=1.1,
|
|
per_kwh=8.8,
|
|
date=start_time.date(),
|
|
nem_time=end_time,
|
|
start_time=start_time,
|
|
end_time=end_time,
|
|
renewables=50,
|
|
channel_type=channel_type.value,
|
|
spike_status=SpikeStatus.NO_SPIKE.value,
|
|
estimate=True,
|
|
)
|
|
|
|
|
|
GENERAL_ONLY_SITE_ID = "01FG2K6V5TB6X9W0EWPPMZD6MJ"
|
|
GENERAL_AND_CONTROLLED_SITE_ID = "01FG2MC8RF7GBC4KJXP3YFZ162"
|
|
GENERAL_AND_FEED_IN_SITE_ID = "01FG2MCD8KTRZR9MNNW84VP50S"
|
|
GENERAL_AND_CONTROLLED_FEED_IN_SITE_ID = "01FG2MCD8KTRZR9MNNW847S50S"
|
|
|
|
GENERAL_CHANNEL = [
|
|
generate_current_interval(
|
|
ChannelType.GENERAL, parser.parse("2021-09-21T08:30:00+10:00")
|
|
),
|
|
generate_forecast_interval(
|
|
ChannelType.GENERAL, parser.parse("2021-09-21T09:00:00+10:00")
|
|
),
|
|
generate_forecast_interval(
|
|
ChannelType.GENERAL, parser.parse("2021-09-21T09:30:00+10:00")
|
|
),
|
|
generate_forecast_interval(
|
|
ChannelType.GENERAL, parser.parse("2021-09-21T10:00:00+10:00")
|
|
),
|
|
]
|
|
|
|
CONTROLLED_LOAD_CHANNEL = [
|
|
generate_current_interval(
|
|
ChannelType.CONTROLLED_LOAD, parser.parse("2021-09-21T08:30:00+10:00")
|
|
),
|
|
generate_forecast_interval(
|
|
ChannelType.CONTROLLED_LOAD, parser.parse("2021-09-21T09:00:00+10:00")
|
|
),
|
|
generate_forecast_interval(
|
|
ChannelType.CONTROLLED_LOAD, parser.parse("2021-09-21T09:30:00+10:00")
|
|
),
|
|
generate_forecast_interval(
|
|
ChannelType.CONTROLLED_LOAD, parser.parse("2021-09-21T10:00:00+10:00")
|
|
),
|
|
]
|
|
|
|
|
|
FEED_IN_CHANNEL = [
|
|
generate_current_interval(
|
|
ChannelType.FEED_IN, parser.parse("2021-09-21T08:30:00+10:00")
|
|
),
|
|
generate_forecast_interval(
|
|
ChannelType.FEED_IN, parser.parse("2021-09-21T09:00:00+10:00")
|
|
),
|
|
generate_forecast_interval(
|
|
ChannelType.FEED_IN, parser.parse("2021-09-21T09:30:00+10:00")
|
|
),
|
|
generate_forecast_interval(
|
|
ChannelType.FEED_IN, parser.parse("2021-09-21T10:00:00+10:00")
|
|
),
|
|
]
|