diff --git a/homeassistant/components/energyzero/__init__.py b/homeassistant/components/energyzero/__init__.py index 096e312efc0818ea181b91591c46575dcb85574a..0eac874f1ed74b4d7fe66f79209f7c2cbecf7bef 100644 --- a/homeassistant/components/energyzero/__init__.py +++ b/homeassistant/components/energyzero/__init__.py @@ -8,6 +8,7 @@ from homeassistant.exceptions import ConfigEntryNotReady from .const import DOMAIN from .coordinator import EnergyZeroDataUpdateCoordinator +from .services import async_register_services PLATFORMS = [Platform.SENSOR] @@ -25,6 +26,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) + + async_register_services(hass, coordinator) + return True diff --git a/homeassistant/components/energyzero/services.py b/homeassistant/components/energyzero/services.py new file mode 100644 index 0000000000000000000000000000000000000000..fb451c40401f6f8a738f85f9ceeacf433d931e7f --- /dev/null +++ b/homeassistant/components/energyzero/services.py @@ -0,0 +1,129 @@ +"""The EnergyZero services.""" +from __future__ import annotations + +from datetime import date, datetime +from enum import Enum +from functools import partial +from typing import Final + +from energyzero import Electricity, Gas, VatOption +import voluptuous as vol + +from homeassistant.core import ( + HomeAssistant, + ServiceCall, + ServiceResponse, + SupportsResponse, + callback, +) +from homeassistant.exceptions import ServiceValidationError +from homeassistant.util import dt as dt_util + +from .const import DOMAIN +from .coordinator import EnergyZeroDataUpdateCoordinator + +ATTR_START: Final = "start" +ATTR_END: Final = "end" +ATTR_INCL_VAT: Final = "incl_vat" + +GAS_SERVICE_NAME: Final = "get_gas_prices" +ENERGY_SERVICE_NAME: Final = "get_energy_prices" +SERVICE_SCHEMA: Final = vol.Schema( + { + vol.Required(ATTR_INCL_VAT): bool, + vol.Optional(ATTR_START): str, + vol.Optional(ATTR_END): str, + } +) + + +class PriceType(Enum): + """Type of price.""" + + ENERGY = "energy" + GAS = "gas" + + +def __get_date(date_input: str | None) -> date | datetime: + """Get date.""" + if not date_input: + return dt_util.now().date() + + if value := dt_util.parse_datetime(date_input): + return value + + raise ServiceValidationError( + "Invalid datetime provided.", + translation_domain=DOMAIN, + translation_key="invalid_date", + translation_placeholders={ + "date": date_input, + }, + ) + + +def __serialize_prices(prices: Electricity | Gas) -> ServiceResponse: + """Serialize prices.""" + return { + "prices": [ + { + key: str(value) if isinstance(value, datetime) else value + for key, value in timestamp_price.items() + } + for timestamp_price in prices.timestamp_prices + ] + } + + +async def __get_prices( + call: ServiceCall, + *, + coordinator: EnergyZeroDataUpdateCoordinator, + price_type: PriceType, +) -> ServiceResponse: + start = __get_date(call.data.get(ATTR_START)) + end = __get_date(call.data.get(ATTR_END)) + + vat = VatOption.INCLUDE + + if call.data.get(ATTR_INCL_VAT) is False: + vat = VatOption.EXCLUDE + + data: Electricity | Gas + + if price_type == PriceType.GAS: + data = await coordinator.energyzero.gas_prices( + start_date=start, + end_date=end, + vat=vat, + ) + else: + data = await coordinator.energyzero.energy_prices( + start_date=start, + end_date=end, + vat=vat, + ) + + return __serialize_prices(data) + + +@callback +def async_register_services( + hass: HomeAssistant, coordinator: EnergyZeroDataUpdateCoordinator +): + """Set up EnergyZero services.""" + + hass.services.async_register( + DOMAIN, + GAS_SERVICE_NAME, + partial(__get_prices, coordinator=coordinator, price_type=PriceType.GAS), + schema=SERVICE_SCHEMA, + supports_response=SupportsResponse.ONLY, + ) + hass.services.async_register( + DOMAIN, + ENERGY_SERVICE_NAME, + partial(__get_prices, coordinator=coordinator, price_type=PriceType.ENERGY), + schema=SERVICE_SCHEMA, + supports_response=SupportsResponse.ONLY, + ) diff --git a/homeassistant/components/energyzero/services.yaml b/homeassistant/components/energyzero/services.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1bcc5ae34bef01f54559de4c3c38b3dd3d7ee627 --- /dev/null +++ b/homeassistant/components/energyzero/services.yaml @@ -0,0 +1,34 @@ +get_gas_prices: + fields: + incl_vat: + required: true + default: true + selector: + boolean: + start: + required: false + example: "2023-01-01 00:00:00" + selector: + datetime: + end: + required: false + example: "2023-01-01 00:00:00" + selector: + datetime: +get_energy_prices: + fields: + incl_vat: + required: true + default: true + selector: + boolean: + start: + required: false + example: "2023-01-01 00:00:00" + selector: + datetime: + end: + required: false + example: "2023-01-01 00:00:00" + selector: + datetime: diff --git a/homeassistant/components/energyzero/strings.json b/homeassistant/components/energyzero/strings.json index a27ce236c281e3798664b410ab19cad2c5773d40..81f54f4222ad628d578e0fee1693675dc2769ffa 100644 --- a/homeassistant/components/energyzero/strings.json +++ b/homeassistant/components/energyzero/strings.json @@ -9,6 +9,11 @@ "already_configured": "[%key:common::config_flow::abort::already_configured_device%]" } }, + "exceptions": { + "invalid_date": { + "message": "Invalid date provided. Got {date}" + } + }, "entity": { "sensor": { "current_hour_price": { @@ -39,5 +44,43 @@ "name": "Hours priced equal or lower than current - today" } } + }, + "services": { + "get_gas_prices": { + "name": "Get gas prices", + "description": "Request gas prices from EnergyZero.", + "fields": { + "incl_vat": { + "name": "Including VAT", + "description": "Include VAT in the prices." + }, + "start": { + "name": "Start", + "description": "Specifies the date and time from which to retrieve prices. Defaults to today if omitted." + }, + "end": { + "name": "End", + "description": "Specifies the date and time until which to retrieve prices. Defaults to today if omitted." + } + } + }, + "get_energy_prices": { + "name": "Get energy prices", + "description": "Request energy prices from EnergyZero.", + "fields": { + "incl_vat": { + "name": "[%key:component::energyzero::services::get_gas_prices::fields::incl_vat::name%]", + "description": "[%key:component::energyzero::services::get_gas_prices::fields::incl_vat::description%]" + }, + "start": { + "name": "[%key:component::energyzero::services::get_gas_prices::fields::start::name%]", + "description": "[%key:component::energyzero::services::get_gas_prices::fields::start::description%]" + }, + "end": { + "name": "[%key:component::energyzero::services::get_gas_prices::fields::end::name%]", + "description": "[%key:component::energyzero::services::get_gas_prices::fields::end::description%]" + } + } + } } } diff --git a/tests/components/energyzero/snapshots/test_services.ambr b/tests/components/energyzero/snapshots/test_services.ambr new file mode 100644 index 0000000000000000000000000000000000000000..73d161477d0ba20850dab813137abee73941df2b --- /dev/null +++ b/tests/components/energyzero/snapshots/test_services.ambr @@ -0,0 +1,2401 @@ +# serializer version: 1 +# name: test_service[end0-start0-incl_vat0-get_energy_prices] + dict({ + 'prices': list([ + dict({ + 'price': 0.35, + 'timestamp': '2022-12-06 23:00:00+00:00', + }), + dict({ + 'price': 0.32, + 'timestamp': '2022-12-07 00:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 01:00:00+00:00', + }), + dict({ + 'price': 0.26, + 'timestamp': '2022-12-07 02:00:00+00:00', + }), + dict({ + 'price': 0.27, + 'timestamp': '2022-12-07 03:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 04:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 05:00:00+00:00', + }), + dict({ + 'price': 0.38, + 'timestamp': '2022-12-07 06:00:00+00:00', + }), + dict({ + 'price': 0.41, + 'timestamp': '2022-12-07 07:00:00+00:00', + }), + dict({ + 'price': 0.46, + 'timestamp': '2022-12-07 08:00:00+00:00', + }), + dict({ + 'price': 0.44, + 'timestamp': '2022-12-07 09:00:00+00:00', + }), + dict({ + 'price': 0.39, + 'timestamp': '2022-12-07 10:00:00+00:00', + }), + dict({ + 'price': 0.33, + 'timestamp': '2022-12-07 11:00:00+00:00', + }), + dict({ + 'price': 0.37, + 'timestamp': '2022-12-07 12:00:00+00:00', + }), + dict({ + 'price': 0.44, + 'timestamp': '2022-12-07 13:00:00+00:00', + }), + dict({ + 'price': 0.48, + 'timestamp': '2022-12-07 14:00:00+00:00', + }), + dict({ + 'price': 0.49, + 'timestamp': '2022-12-07 15:00:00+00:00', + }), + dict({ + 'price': 0.55, + 'timestamp': '2022-12-07 16:00:00+00:00', + }), + dict({ + 'price': 0.37, + 'timestamp': '2022-12-07 17:00:00+00:00', + }), + dict({ + 'price': 0.4, + 'timestamp': '2022-12-07 18:00:00+00:00', + }), + dict({ + 'price': 0.4, + 'timestamp': '2022-12-07 19:00:00+00:00', + }), + dict({ + 'price': 0.32, + 'timestamp': '2022-12-07 20:00:00+00:00', + }), + dict({ + 'price': 0.33, + 'timestamp': '2022-12-07 21:00:00+00:00', + }), + dict({ + 'price': 0.31, + 'timestamp': '2022-12-07 22:00:00+00:00', + }), + ]), + }) +# --- +# name: test_service[end0-start0-incl_vat0-get_gas_prices] + dict({ + 'prices': list([ + dict({ + 'price': 1.43, + 'timestamp': '2022-12-05 23:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 00:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 01:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 02:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 03:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 04:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 05:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 06:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 07:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 08:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 09:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 10:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 11:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 12:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 13:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 14:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 15:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 16:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 17:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 18:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 19:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 20:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 21:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 22:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 23:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 00:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 01:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 02:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 03:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 04:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 05:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 06:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 07:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 08:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 09:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 10:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 11:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 12:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 13:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 14:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 15:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 16:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 17:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 18:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 19:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 20:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 21:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 22:00:00+00:00', + }), + ]), + }) +# --- +# name: test_service[end0-start0-incl_vat1-get_energy_prices] + dict({ + 'prices': list([ + dict({ + 'price': 0.35, + 'timestamp': '2022-12-06 23:00:00+00:00', + }), + dict({ + 'price': 0.32, + 'timestamp': '2022-12-07 00:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 01:00:00+00:00', + }), + dict({ + 'price': 0.26, + 'timestamp': '2022-12-07 02:00:00+00:00', + }), + dict({ + 'price': 0.27, + 'timestamp': '2022-12-07 03:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 04:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 05:00:00+00:00', + }), + dict({ + 'price': 0.38, + 'timestamp': '2022-12-07 06:00:00+00:00', + }), + dict({ + 'price': 0.41, + 'timestamp': '2022-12-07 07:00:00+00:00', + }), + dict({ + 'price': 0.46, + 'timestamp': '2022-12-07 08:00:00+00:00', + }), + dict({ + 'price': 0.44, + 'timestamp': '2022-12-07 09:00:00+00:00', + }), + dict({ + 'price': 0.39, + 'timestamp': '2022-12-07 10:00:00+00:00', + }), + dict({ + 'price': 0.33, + 'timestamp': '2022-12-07 11:00:00+00:00', + }), + dict({ + 'price': 0.37, + 'timestamp': '2022-12-07 12:00:00+00:00', + }), + dict({ + 'price': 0.44, + 'timestamp': '2022-12-07 13:00:00+00:00', + }), + dict({ + 'price': 0.48, + 'timestamp': '2022-12-07 14:00:00+00:00', + }), + dict({ + 'price': 0.49, + 'timestamp': '2022-12-07 15:00:00+00:00', + }), + dict({ + 'price': 0.55, + 'timestamp': '2022-12-07 16:00:00+00:00', + }), + dict({ + 'price': 0.37, + 'timestamp': '2022-12-07 17:00:00+00:00', + }), + dict({ + 'price': 0.4, + 'timestamp': '2022-12-07 18:00:00+00:00', + }), + dict({ + 'price': 0.4, + 'timestamp': '2022-12-07 19:00:00+00:00', + }), + dict({ + 'price': 0.32, + 'timestamp': '2022-12-07 20:00:00+00:00', + }), + dict({ + 'price': 0.33, + 'timestamp': '2022-12-07 21:00:00+00:00', + }), + dict({ + 'price': 0.31, + 'timestamp': '2022-12-07 22:00:00+00:00', + }), + ]), + }) +# --- +# name: test_service[end0-start0-incl_vat1-get_gas_prices] + dict({ + 'prices': list([ + dict({ + 'price': 1.43, + 'timestamp': '2022-12-05 23:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 00:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 01:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 02:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 03:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 04:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 05:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 06:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 07:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 08:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 09:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 10:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 11:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 12:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 13:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 14:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 15:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 16:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 17:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 18:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 19:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 20:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 21:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 22:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 23:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 00:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 01:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 02:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 03:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 04:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 05:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 06:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 07:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 08:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 09:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 10:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 11:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 12:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 13:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 14:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 15:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 16:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 17:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 18:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 19:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 20:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 21:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 22:00:00+00:00', + }), + ]), + }) +# --- +# name: test_service[end0-start1-incl_vat0-get_energy_prices] + dict({ + 'prices': list([ + dict({ + 'price': 0.35, + 'timestamp': '2022-12-06 23:00:00+00:00', + }), + dict({ + 'price': 0.32, + 'timestamp': '2022-12-07 00:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 01:00:00+00:00', + }), + dict({ + 'price': 0.26, + 'timestamp': '2022-12-07 02:00:00+00:00', + }), + dict({ + 'price': 0.27, + 'timestamp': '2022-12-07 03:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 04:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 05:00:00+00:00', + }), + dict({ + 'price': 0.38, + 'timestamp': '2022-12-07 06:00:00+00:00', + }), + dict({ + 'price': 0.41, + 'timestamp': '2022-12-07 07:00:00+00:00', + }), + dict({ + 'price': 0.46, + 'timestamp': '2022-12-07 08:00:00+00:00', + }), + dict({ + 'price': 0.44, + 'timestamp': '2022-12-07 09:00:00+00:00', + }), + dict({ + 'price': 0.39, + 'timestamp': '2022-12-07 10:00:00+00:00', + }), + dict({ + 'price': 0.33, + 'timestamp': '2022-12-07 11:00:00+00:00', + }), + dict({ + 'price': 0.37, + 'timestamp': '2022-12-07 12:00:00+00:00', + }), + dict({ + 'price': 0.44, + 'timestamp': '2022-12-07 13:00:00+00:00', + }), + dict({ + 'price': 0.48, + 'timestamp': '2022-12-07 14:00:00+00:00', + }), + dict({ + 'price': 0.49, + 'timestamp': '2022-12-07 15:00:00+00:00', + }), + dict({ + 'price': 0.55, + 'timestamp': '2022-12-07 16:00:00+00:00', + }), + dict({ + 'price': 0.37, + 'timestamp': '2022-12-07 17:00:00+00:00', + }), + dict({ + 'price': 0.4, + 'timestamp': '2022-12-07 18:00:00+00:00', + }), + dict({ + 'price': 0.4, + 'timestamp': '2022-12-07 19:00:00+00:00', + }), + dict({ + 'price': 0.32, + 'timestamp': '2022-12-07 20:00:00+00:00', + }), + dict({ + 'price': 0.33, + 'timestamp': '2022-12-07 21:00:00+00:00', + }), + dict({ + 'price': 0.31, + 'timestamp': '2022-12-07 22:00:00+00:00', + }), + ]), + }) +# --- +# name: test_service[end0-start1-incl_vat0-get_gas_prices] + dict({ + 'prices': list([ + dict({ + 'price': 1.43, + 'timestamp': '2022-12-05 23:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 00:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 01:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 02:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 03:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 04:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 05:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 06:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 07:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 08:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 09:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 10:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 11:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 12:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 13:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 14:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 15:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 16:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 17:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 18:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 19:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 20:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 21:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 22:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 23:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 00:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 01:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 02:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 03:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 04:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 05:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 06:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 07:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 08:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 09:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 10:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 11:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 12:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 13:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 14:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 15:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 16:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 17:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 18:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 19:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 20:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 21:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 22:00:00+00:00', + }), + ]), + }) +# --- +# name: test_service[end0-start1-incl_vat1-get_energy_prices] + dict({ + 'prices': list([ + dict({ + 'price': 0.35, + 'timestamp': '2022-12-06 23:00:00+00:00', + }), + dict({ + 'price': 0.32, + 'timestamp': '2022-12-07 00:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 01:00:00+00:00', + }), + dict({ + 'price': 0.26, + 'timestamp': '2022-12-07 02:00:00+00:00', + }), + dict({ + 'price': 0.27, + 'timestamp': '2022-12-07 03:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 04:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 05:00:00+00:00', + }), + dict({ + 'price': 0.38, + 'timestamp': '2022-12-07 06:00:00+00:00', + }), + dict({ + 'price': 0.41, + 'timestamp': '2022-12-07 07:00:00+00:00', + }), + dict({ + 'price': 0.46, + 'timestamp': '2022-12-07 08:00:00+00:00', + }), + dict({ + 'price': 0.44, + 'timestamp': '2022-12-07 09:00:00+00:00', + }), + dict({ + 'price': 0.39, + 'timestamp': '2022-12-07 10:00:00+00:00', + }), + dict({ + 'price': 0.33, + 'timestamp': '2022-12-07 11:00:00+00:00', + }), + dict({ + 'price': 0.37, + 'timestamp': '2022-12-07 12:00:00+00:00', + }), + dict({ + 'price': 0.44, + 'timestamp': '2022-12-07 13:00:00+00:00', + }), + dict({ + 'price': 0.48, + 'timestamp': '2022-12-07 14:00:00+00:00', + }), + dict({ + 'price': 0.49, + 'timestamp': '2022-12-07 15:00:00+00:00', + }), + dict({ + 'price': 0.55, + 'timestamp': '2022-12-07 16:00:00+00:00', + }), + dict({ + 'price': 0.37, + 'timestamp': '2022-12-07 17:00:00+00:00', + }), + dict({ + 'price': 0.4, + 'timestamp': '2022-12-07 18:00:00+00:00', + }), + dict({ + 'price': 0.4, + 'timestamp': '2022-12-07 19:00:00+00:00', + }), + dict({ + 'price': 0.32, + 'timestamp': '2022-12-07 20:00:00+00:00', + }), + dict({ + 'price': 0.33, + 'timestamp': '2022-12-07 21:00:00+00:00', + }), + dict({ + 'price': 0.31, + 'timestamp': '2022-12-07 22:00:00+00:00', + }), + ]), + }) +# --- +# name: test_service[end0-start1-incl_vat1-get_gas_prices] + dict({ + 'prices': list([ + dict({ + 'price': 1.43, + 'timestamp': '2022-12-05 23:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 00:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 01:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 02:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 03:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 04:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 05:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 06:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 07:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 08:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 09:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 10:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 11:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 12:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 13:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 14:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 15:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 16:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 17:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 18:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 19:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 20:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 21:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 22:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 23:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 00:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 01:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 02:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 03:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 04:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 05:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 06:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 07:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 08:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 09:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 10:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 11:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 12:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 13:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 14:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 15:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 16:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 17:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 18:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 19:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 20:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 21:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 22:00:00+00:00', + }), + ]), + }) +# --- +# name: test_service[end1-start0-incl_vat0-get_energy_prices] + dict({ + 'prices': list([ + dict({ + 'price': 0.35, + 'timestamp': '2022-12-06 23:00:00+00:00', + }), + dict({ + 'price': 0.32, + 'timestamp': '2022-12-07 00:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 01:00:00+00:00', + }), + dict({ + 'price': 0.26, + 'timestamp': '2022-12-07 02:00:00+00:00', + }), + dict({ + 'price': 0.27, + 'timestamp': '2022-12-07 03:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 04:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 05:00:00+00:00', + }), + dict({ + 'price': 0.38, + 'timestamp': '2022-12-07 06:00:00+00:00', + }), + dict({ + 'price': 0.41, + 'timestamp': '2022-12-07 07:00:00+00:00', + }), + dict({ + 'price': 0.46, + 'timestamp': '2022-12-07 08:00:00+00:00', + }), + dict({ + 'price': 0.44, + 'timestamp': '2022-12-07 09:00:00+00:00', + }), + dict({ + 'price': 0.39, + 'timestamp': '2022-12-07 10:00:00+00:00', + }), + dict({ + 'price': 0.33, + 'timestamp': '2022-12-07 11:00:00+00:00', + }), + dict({ + 'price': 0.37, + 'timestamp': '2022-12-07 12:00:00+00:00', + }), + dict({ + 'price': 0.44, + 'timestamp': '2022-12-07 13:00:00+00:00', + }), + dict({ + 'price': 0.48, + 'timestamp': '2022-12-07 14:00:00+00:00', + }), + dict({ + 'price': 0.49, + 'timestamp': '2022-12-07 15:00:00+00:00', + }), + dict({ + 'price': 0.55, + 'timestamp': '2022-12-07 16:00:00+00:00', + }), + dict({ + 'price': 0.37, + 'timestamp': '2022-12-07 17:00:00+00:00', + }), + dict({ + 'price': 0.4, + 'timestamp': '2022-12-07 18:00:00+00:00', + }), + dict({ + 'price': 0.4, + 'timestamp': '2022-12-07 19:00:00+00:00', + }), + dict({ + 'price': 0.32, + 'timestamp': '2022-12-07 20:00:00+00:00', + }), + dict({ + 'price': 0.33, + 'timestamp': '2022-12-07 21:00:00+00:00', + }), + dict({ + 'price': 0.31, + 'timestamp': '2022-12-07 22:00:00+00:00', + }), + ]), + }) +# --- +# name: test_service[end1-start0-incl_vat0-get_gas_prices] + dict({ + 'prices': list([ + dict({ + 'price': 1.43, + 'timestamp': '2022-12-05 23:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 00:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 01:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 02:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 03:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 04:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 05:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 06:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 07:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 08:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 09:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 10:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 11:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 12:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 13:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 14:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 15:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 16:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 17:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 18:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 19:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 20:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 21:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 22:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 23:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 00:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 01:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 02:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 03:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 04:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 05:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 06:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 07:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 08:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 09:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 10:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 11:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 12:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 13:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 14:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 15:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 16:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 17:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 18:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 19:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 20:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 21:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 22:00:00+00:00', + }), + ]), + }) +# --- +# name: test_service[end1-start0-incl_vat1-get_energy_prices] + dict({ + 'prices': list([ + dict({ + 'price': 0.35, + 'timestamp': '2022-12-06 23:00:00+00:00', + }), + dict({ + 'price': 0.32, + 'timestamp': '2022-12-07 00:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 01:00:00+00:00', + }), + dict({ + 'price': 0.26, + 'timestamp': '2022-12-07 02:00:00+00:00', + }), + dict({ + 'price': 0.27, + 'timestamp': '2022-12-07 03:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 04:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 05:00:00+00:00', + }), + dict({ + 'price': 0.38, + 'timestamp': '2022-12-07 06:00:00+00:00', + }), + dict({ + 'price': 0.41, + 'timestamp': '2022-12-07 07:00:00+00:00', + }), + dict({ + 'price': 0.46, + 'timestamp': '2022-12-07 08:00:00+00:00', + }), + dict({ + 'price': 0.44, + 'timestamp': '2022-12-07 09:00:00+00:00', + }), + dict({ + 'price': 0.39, + 'timestamp': '2022-12-07 10:00:00+00:00', + }), + dict({ + 'price': 0.33, + 'timestamp': '2022-12-07 11:00:00+00:00', + }), + dict({ + 'price': 0.37, + 'timestamp': '2022-12-07 12:00:00+00:00', + }), + dict({ + 'price': 0.44, + 'timestamp': '2022-12-07 13:00:00+00:00', + }), + dict({ + 'price': 0.48, + 'timestamp': '2022-12-07 14:00:00+00:00', + }), + dict({ + 'price': 0.49, + 'timestamp': '2022-12-07 15:00:00+00:00', + }), + dict({ + 'price': 0.55, + 'timestamp': '2022-12-07 16:00:00+00:00', + }), + dict({ + 'price': 0.37, + 'timestamp': '2022-12-07 17:00:00+00:00', + }), + dict({ + 'price': 0.4, + 'timestamp': '2022-12-07 18:00:00+00:00', + }), + dict({ + 'price': 0.4, + 'timestamp': '2022-12-07 19:00:00+00:00', + }), + dict({ + 'price': 0.32, + 'timestamp': '2022-12-07 20:00:00+00:00', + }), + dict({ + 'price': 0.33, + 'timestamp': '2022-12-07 21:00:00+00:00', + }), + dict({ + 'price': 0.31, + 'timestamp': '2022-12-07 22:00:00+00:00', + }), + ]), + }) +# --- +# name: test_service[end1-start0-incl_vat1-get_gas_prices] + dict({ + 'prices': list([ + dict({ + 'price': 1.43, + 'timestamp': '2022-12-05 23:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 00:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 01:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 02:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 03:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 04:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 05:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 06:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 07:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 08:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 09:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 10:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 11:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 12:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 13:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 14:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 15:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 16:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 17:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 18:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 19:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 20:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 21:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 22:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 23:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 00:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 01:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 02:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 03:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 04:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 05:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 06:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 07:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 08:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 09:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 10:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 11:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 12:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 13:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 14:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 15:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 16:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 17:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 18:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 19:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 20:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 21:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 22:00:00+00:00', + }), + ]), + }) +# --- +# name: test_service[end1-start1-incl_vat0-get_energy_prices] + dict({ + 'prices': list([ + dict({ + 'price': 0.35, + 'timestamp': '2022-12-06 23:00:00+00:00', + }), + dict({ + 'price': 0.32, + 'timestamp': '2022-12-07 00:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 01:00:00+00:00', + }), + dict({ + 'price': 0.26, + 'timestamp': '2022-12-07 02:00:00+00:00', + }), + dict({ + 'price': 0.27, + 'timestamp': '2022-12-07 03:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 04:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 05:00:00+00:00', + }), + dict({ + 'price': 0.38, + 'timestamp': '2022-12-07 06:00:00+00:00', + }), + dict({ + 'price': 0.41, + 'timestamp': '2022-12-07 07:00:00+00:00', + }), + dict({ + 'price': 0.46, + 'timestamp': '2022-12-07 08:00:00+00:00', + }), + dict({ + 'price': 0.44, + 'timestamp': '2022-12-07 09:00:00+00:00', + }), + dict({ + 'price': 0.39, + 'timestamp': '2022-12-07 10:00:00+00:00', + }), + dict({ + 'price': 0.33, + 'timestamp': '2022-12-07 11:00:00+00:00', + }), + dict({ + 'price': 0.37, + 'timestamp': '2022-12-07 12:00:00+00:00', + }), + dict({ + 'price': 0.44, + 'timestamp': '2022-12-07 13:00:00+00:00', + }), + dict({ + 'price': 0.48, + 'timestamp': '2022-12-07 14:00:00+00:00', + }), + dict({ + 'price': 0.49, + 'timestamp': '2022-12-07 15:00:00+00:00', + }), + dict({ + 'price': 0.55, + 'timestamp': '2022-12-07 16:00:00+00:00', + }), + dict({ + 'price': 0.37, + 'timestamp': '2022-12-07 17:00:00+00:00', + }), + dict({ + 'price': 0.4, + 'timestamp': '2022-12-07 18:00:00+00:00', + }), + dict({ + 'price': 0.4, + 'timestamp': '2022-12-07 19:00:00+00:00', + }), + dict({ + 'price': 0.32, + 'timestamp': '2022-12-07 20:00:00+00:00', + }), + dict({ + 'price': 0.33, + 'timestamp': '2022-12-07 21:00:00+00:00', + }), + dict({ + 'price': 0.31, + 'timestamp': '2022-12-07 22:00:00+00:00', + }), + ]), + }) +# --- +# name: test_service[end1-start1-incl_vat0-get_gas_prices] + dict({ + 'prices': list([ + dict({ + 'price': 1.43, + 'timestamp': '2022-12-05 23:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 00:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 01:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 02:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 03:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 04:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 05:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 06:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 07:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 08:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 09:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 10:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 11:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 12:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 13:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 14:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 15:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 16:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 17:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 18:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 19:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 20:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 21:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 22:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 23:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 00:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 01:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 02:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 03:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 04:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 05:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 06:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 07:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 08:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 09:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 10:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 11:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 12:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 13:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 14:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 15:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 16:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 17:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 18:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 19:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 20:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 21:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 22:00:00+00:00', + }), + ]), + }) +# --- +# name: test_service[end1-start1-incl_vat1-get_energy_prices] + dict({ + 'prices': list([ + dict({ + 'price': 0.35, + 'timestamp': '2022-12-06 23:00:00+00:00', + }), + dict({ + 'price': 0.32, + 'timestamp': '2022-12-07 00:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 01:00:00+00:00', + }), + dict({ + 'price': 0.26, + 'timestamp': '2022-12-07 02:00:00+00:00', + }), + dict({ + 'price': 0.27, + 'timestamp': '2022-12-07 03:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 04:00:00+00:00', + }), + dict({ + 'price': 0.28, + 'timestamp': '2022-12-07 05:00:00+00:00', + }), + dict({ + 'price': 0.38, + 'timestamp': '2022-12-07 06:00:00+00:00', + }), + dict({ + 'price': 0.41, + 'timestamp': '2022-12-07 07:00:00+00:00', + }), + dict({ + 'price': 0.46, + 'timestamp': '2022-12-07 08:00:00+00:00', + }), + dict({ + 'price': 0.44, + 'timestamp': '2022-12-07 09:00:00+00:00', + }), + dict({ + 'price': 0.39, + 'timestamp': '2022-12-07 10:00:00+00:00', + }), + dict({ + 'price': 0.33, + 'timestamp': '2022-12-07 11:00:00+00:00', + }), + dict({ + 'price': 0.37, + 'timestamp': '2022-12-07 12:00:00+00:00', + }), + dict({ + 'price': 0.44, + 'timestamp': '2022-12-07 13:00:00+00:00', + }), + dict({ + 'price': 0.48, + 'timestamp': '2022-12-07 14:00:00+00:00', + }), + dict({ + 'price': 0.49, + 'timestamp': '2022-12-07 15:00:00+00:00', + }), + dict({ + 'price': 0.55, + 'timestamp': '2022-12-07 16:00:00+00:00', + }), + dict({ + 'price': 0.37, + 'timestamp': '2022-12-07 17:00:00+00:00', + }), + dict({ + 'price': 0.4, + 'timestamp': '2022-12-07 18:00:00+00:00', + }), + dict({ + 'price': 0.4, + 'timestamp': '2022-12-07 19:00:00+00:00', + }), + dict({ + 'price': 0.32, + 'timestamp': '2022-12-07 20:00:00+00:00', + }), + dict({ + 'price': 0.33, + 'timestamp': '2022-12-07 21:00:00+00:00', + }), + dict({ + 'price': 0.31, + 'timestamp': '2022-12-07 22:00:00+00:00', + }), + ]), + }) +# --- +# name: test_service[end1-start1-incl_vat1-get_gas_prices] + dict({ + 'prices': list([ + dict({ + 'price': 1.43, + 'timestamp': '2022-12-05 23:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 00:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 01:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 02:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 03:00:00+00:00', + }), + dict({ + 'price': 1.43, + 'timestamp': '2022-12-06 04:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 05:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 06:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 07:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 08:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 09:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 10:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 11:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 12:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 13:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 14:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 15:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 16:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 17:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 18:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 19:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 20:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 21:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 22:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-06 23:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 00:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 01:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 02:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 03:00:00+00:00', + }), + dict({ + 'price': 1.45, + 'timestamp': '2022-12-07 04:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 05:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 06:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 07:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 08:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 09:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 10:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 11:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 12:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 13:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 14:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 15:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 16:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 17:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 18:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 19:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 20:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 21:00:00+00:00', + }), + dict({ + 'price': 1.47, + 'timestamp': '2022-12-07 22:00:00+00:00', + }), + ]), + }) +# --- diff --git a/tests/components/energyzero/test_services.py b/tests/components/energyzero/test_services.py new file mode 100644 index 0000000000000000000000000000000000000000..7939b06ce8e0e33268baf33740cf7c6ab54efcac --- /dev/null +++ b/tests/components/energyzero/test_services.py @@ -0,0 +1,90 @@ +"""Tests for the services provided by the EnergyZero integration.""" + +import pytest +from syrupy.assertion import SnapshotAssertion +import voluptuous as vol + +from homeassistant.components.energyzero.const import DOMAIN +from homeassistant.components.energyzero.services import ( + ENERGY_SERVICE_NAME, + GAS_SERVICE_NAME, +) +from homeassistant.core import HomeAssistant +from homeassistant.exceptions import ServiceValidationError + + +@pytest.mark.usefixtures("init_integration") +async def test_has_services( + hass: HomeAssistant, +) -> None: + """Test the existence of the EnergyZero Service.""" + assert hass.services.has_service(DOMAIN, GAS_SERVICE_NAME) + assert hass.services.has_service(DOMAIN, ENERGY_SERVICE_NAME) + + +@pytest.mark.usefixtures("init_integration") +@pytest.mark.parametrize("service", [GAS_SERVICE_NAME, ENERGY_SERVICE_NAME]) +@pytest.mark.parametrize("incl_vat", [{"incl_vat": False}, {"incl_vat": True}]) +@pytest.mark.parametrize("start", [{"start": "2023-01-01 00:00:00"}, {}]) +@pytest.mark.parametrize("end", [{"end": "2023-01-01 00:00:00"}, {}]) +async def test_service( + hass: HomeAssistant, + snapshot: SnapshotAssertion, + service: str, + incl_vat: dict[str, bool], + start: dict[str, str], + end: dict[str, str], +) -> None: + """Test the EnergyZero Service.""" + + data = incl_vat | start | end + + assert snapshot == await hass.services.async_call( + DOMAIN, + service, + data, + blocking=True, + return_response=True, + ) + + +@pytest.mark.usefixtures("init_integration") +@pytest.mark.parametrize("service", [GAS_SERVICE_NAME, ENERGY_SERVICE_NAME]) +@pytest.mark.parametrize( + ("service_data", "error", "error_message"), + [ + ({}, vol.er.Error, "required key not provided .+"), + ( + {"incl_vat": "incorrect vat"}, + vol.er.Error, + "expected bool for dictionary value .+", + ), + ( + {"incl_vat": True, "start": "incorrect date"}, + ServiceValidationError, + "Invalid datetime provided.", + ), + ( + {"incl_vat": True, "end": "incorrect date"}, + ServiceValidationError, + "Invalid datetime provided.", + ), + ], +) +async def test_service_validation( + hass: HomeAssistant, + service: str, + service_data: dict[str, str], + error: type[Exception], + error_message: str, +) -> None: + """Test the EnergyZero Service validation.""" + + with pytest.raises(error, match=error_message): + await hass.services.async_call( + DOMAIN, + service, + service_data, + blocking=True, + return_response=True, + )