Skip to content

Commit

Permalink
Add watermeter as optional service
Browse files Browse the repository at this point in the history
  • Loading branch information
klaasnicolaas committed Aug 14, 2022
1 parent 04545f9 commit 996af1f
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 196 deletions.
4 changes: 4 additions & 0 deletions homeassistant/components/p1_monitor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from .const import (
CONF_WATERMETER,
DOMAIN,
LOGGER,
SCAN_INTERVAL,
SERVICE_PHASES,
SERVICE_SETTINGS,
SERVICE_SMARTMETER,
SERVICE_WATERMETER,
)

PLATFORMS = [Platform.SENSOR]
Expand Down Expand Up @@ -85,5 +87,7 @@ async def _async_update_data(self) -> P1MonitorData:
SERVICE_PHASES: await self.p1monitor.phases(),
SERVICE_SETTINGS: await self.p1monitor.settings(),
}
if self.config_entry.data[CONF_WATERMETER]:
data[SERVICE_WATERMETER] = await self.p1monitor.watermeter()

return data
4 changes: 3 additions & 1 deletion homeassistant/components/p1_monitor/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.aiohttp_client import async_get_clientsession

from .const import DOMAIN
from .const import CONF_WATERMETER, DOMAIN


class P1MonitorFlowHandler(ConfigFlow, domain=DOMAIN):
Expand Down Expand Up @@ -40,6 +40,7 @@ async def async_step_user(
title=user_input[CONF_NAME],
data={
CONF_HOST: user_input[CONF_HOST],
CONF_WATERMETER: user_input[CONF_WATERMETER],
},
)

Expand All @@ -51,6 +52,7 @@ async def async_step_user(
CONF_NAME, default=self.hass.config.location_name
): str,
vol.Required(CONF_HOST): str,
vol.Optional(CONF_WATERMETER, default=False): bool,
}
),
errors=errors,
Expand Down
14 changes: 9 additions & 5 deletions homeassistant/components/p1_monitor/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
LOGGER = logging.getLogger(__package__)
SCAN_INTERVAL = timedelta(seconds=5)

CONF_WATERMETER: Final = "watermeter"

SERVICE_SMARTMETER: Final = "smartmeter"
SERVICE_WATERMETER: Final = "watermeter"
SERVICE_PHASES: Final = "phases"
SERVICE_SETTINGS: Final = "settings"

SERVICES: dict[str, str] = {
SERVICE_SMARTMETER: "SmartMeter",
SERVICE_PHASES: "Phases",
SERVICE_SETTINGS: "Settings",
}
# SERVICES: dict[str, str] = {
# SERVICE_SMARTMETER: "SmartMeter",
# SERVICE_WATERMETER: "WaterMeter",
# SERVICE_PHASES: "Phases",
# SERVICE_SETTINGS: "Settings",
# }

0 comments on commit 996af1f

Please sign in to comment.