diff --git a/custom_components/senec/__init__.py b/custom_components/senec/__init__.py index ce6a10d..f9e7f85 100644 --- a/custom_components/senec/__init__.py +++ b/custom_components/senec/__init__.py @@ -59,6 +59,8 @@ QUERY_WALLBOX_KEY, QUERY_SPARE_CAPACITY_KEY, QUERY_PEAK_SHAVING_KEY, + + SERVICE_SET_PEAKSHAVING, ) _LOGGER = logging.getLogger(__name__) @@ -118,7 +120,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry): # Register Services service = SenecService.SenecService(hass, config_entry, coordinator) - hass.services.async_register(DOMAIN, "set_peakshaving", service.set_peakshaving) + hass.services.async_register(DOMAIN, SERVICE_SET_PEAKSHAVING, service.set_peakshaving) hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][config_entry.entry_id] = coordinator @@ -294,6 +296,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry): ) if unload_ok: hass.data[DOMAIN].pop(config_entry.entry_id) + hass.services.async_remove(DOMAIN, SERVICE_SET_PEAKSHAVING) # Remove Service on unload return unload_ok diff --git a/custom_components/senec/const.py b/custom_components/senec/const.py index fdca74b..a5a14ba 100644 --- a/custom_components/senec/const.py +++ b/custom_components/senec/const.py @@ -99,6 +99,8 @@ # Peak Shaving Options PEAK_SHAVING_OPTIONS = ["deactivated", "manual", "auto"] +# Service names +SERVICE_SET_PEAKSHAVING: Final = "set_peakshaving" @dataclass class ExtSensorEntityDescription(SensorEntityDescription): diff --git a/custom_components/senec/service.py b/custom_components/senec/service.py index 74d503b..14f50a6 100644 --- a/custom_components/senec/service.py +++ b/custom_components/senec/service.py @@ -1,8 +1,6 @@ """ Services for SENEC Device""" from datetime import datetime -from homeassistant.util import slugify -from homeassistant.config_entries import ConfigEntry class SenecService():