Skip to content

Commit

Permalink
fix: Fixed registration of update target rate config service
Browse files Browse the repository at this point in the history
  • Loading branch information
BottlecapDave committed Apr 27, 2024
1 parent f0f7aa7 commit 02f89ee
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions custom_components/carbon_intensity/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from datetime import timedelta
import logging
from .target_rates.target_rate import CarbonIntensityTargetRate

import voluptuous as vol

from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.exceptions import ConfigEntryNotReady

from .const import (
DOMAIN,

CONFIG_TARGET_NAME,

DATA_RATES_COORDINATOR
)
from .target_rates.target_rate import CarbonIntensityTargetRate

_LOGGER = logging.getLogger(__name__)

Expand All @@ -35,4 +36,25 @@ async def async_setup_target_sensors(hass, entry, async_add_entities):

coordinator = hass.data[DOMAIN][DATA_RATES_COORDINATOR]

async_add_entities([CarbonIntensityTargetRate(coordinator, config)], True)
platform = entity_platform.async_get_current_platform()
platform.async_register_entity_service(
"update_target_config",
vol.All(
vol.Schema(
{
vol.Optional("target_hours"): str,
vol.Optional("target_start_time"): str,
vol.Optional("target_end_time"): str,
vol.Optional("target_offset"): str,
vol.Optional("target_maximum_rate"): str,
},
extra=vol.ALLOW_EXTRA,
),
cv.has_at_least_one_key(
"target_hours", "target_start_time", "target_end_time", "target_offset", "target_maximum_rate"
),
),
"async_update_config",
)

async_add_entities([CarbonIntensityTargetRate(hass, coordinator, config)], True)

0 comments on commit 02f89ee

Please sign in to comment.