Skip to content

Commit

Permalink
Refactoring of Service set_peakshaving
Browse files Browse the repository at this point in the history
  • Loading branch information
io-debug committed Oct 26, 2023
1 parent 6dfdd47 commit 3848347
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion custom_components/senec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
QUERY_WALLBOX_KEY,
QUERY_SPARE_CAPACITY_KEY,
QUERY_PEAK_SHAVING_KEY,

SERVICE_SET_PEAKSHAVING,
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
2 changes: 2 additions & 0 deletions custom_components/senec/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions custom_components/senec/service.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down

0 comments on commit 3848347

Please sign in to comment.