Skip to content

Commit

Permalink
black format
Browse files Browse the repository at this point in the history
  • Loading branch information
magnuselden authored and magnuselden committed Sep 11, 2024
1 parent 4513794 commit 6de9c7b
Show file tree
Hide file tree
Showing 68 changed files with 1,778 additions and 616 deletions.
30 changes: 24 additions & 6 deletions custom_components/peaqhvac/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The peaqhvac integration."""

from __future__ import annotations

import logging
Expand All @@ -16,9 +17,11 @@

_LOGGER = logging.getLogger(__name__)


async def async_get_existing_param(conf, parameter: str, default_val: any):
return conf.options.get(parameter, conf.data.get(parameter, default_val))


async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][config.entry_id] = config.data
Expand All @@ -31,12 +34,26 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:
huboptions.outdoor_tempsensors = huboptions.set_sensors_from_string(
await async_get_existing_param(config, "outdoor_tempsensors", "")
)
huboptions.heating_options.outdoor_temp_stop_heating = await async_get_existing_param(config, "outdoor_temp_stop_heating", 15)
huboptions.heating_options.non_hours_water_boost = await async_get_existing_param(config, "non_hours_water_boost",[])
huboptions.heating_options.demand_hours_water_boost = await async_get_existing_param(config, "demand_hours_water_boost",[])
huboptions.heating_options.outdoor_temp_stop_heating = (
await async_get_existing_param(config, "outdoor_temp_stop_heating", 15)
)
huboptions.heating_options.non_hours_water_boost = await async_get_existing_param(
config, "non_hours_water_boost", []
)
huboptions.heating_options.demand_hours_water_boost = (
await async_get_existing_param(config, "demand_hours_water_boost", [])
)

huboptions.heating_options.low_degree_minutes = int((await async_get_existing_param(config, "low_degree_minutes","-600")).replace(" ", ""))
huboptions.heating_options.very_cold_temp = int((await async_get_existing_param(config, "very_cold_temp","-12")).replace(" ", ""))
huboptions.heating_options.low_degree_minutes = int(
(await async_get_existing_param(config, "low_degree_minutes", "-600")).replace(
" ", ""
)
)
huboptions.heating_options.very_cold_temp = int(
(await async_get_existing_param(config, "very_cold_temp", "-12")).replace(
" ", ""
)
)
huboptions.systemid = config.data["systemid"]

huboptions.hvacbrand = huboptions.set_hvacbrand(
Expand All @@ -47,7 +64,7 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:

hass.data[DOMAIN]["hub"] = hub

#await hub.async_setup()
# await hub.async_setup()
await async_setup_services(hass, hub)

await hass.config_entries.async_forward_entry_setups(config, PLATFORMS)
Expand All @@ -71,6 +88,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok


async def async_update_entry(hass: HomeAssistant, config_entry: ConfigEntry):
"""Reload Peaqev component when options changed."""
_LOGGER.debug("Reloading PeaqHvac component")
Expand Down
20 changes: 14 additions & 6 deletions custom_components/peaqhvac/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
from datetime import timedelta

from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import (PRESET_AWAY, PRESET_ECO,
PRESET_NONE,
HVACAction, HVACMode, ClimateEntityFeature)
from homeassistant.components.climate.const import (
PRESET_AWAY,
PRESET_ECO,
PRESET_NONE,
HVACAction,
HVACMode,
ClimateEntityFeature,
)
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.restore_state import RestoreEntity

import custom_components.peaqhvac.extensionmethods as ex
from custom_components.peaqhvac.const import CLIMATE_SENSOR, DOMAIN
from custom_components.peaqhvac.service.models.enums.hvacmode import \
HvacMode as HvacModeInternal
from custom_components.peaqhvac.service.models.enums.hvacmode import (
HvacMode as HvacModeInternal,
)

_LOGGER = logging.getLogger(__name__)
SCAN_INTERVAL = timedelta(seconds=10)
Expand Down Expand Up @@ -45,7 +51,9 @@ def __init__(self, hass, entry_id, hub, name):

@property
def supported_features(self):
return ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
return (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
)

@property
def name(self):
Expand Down
62 changes: 43 additions & 19 deletions custom_components/peaqhvac/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
"""Config flow for Peaq integration."""

from __future__ import annotations

import logging
from typing import Any, Optional
import homeassistant.helpers.config_validation as cv # pylint: disable=E0401
import homeassistant.helpers.config_validation as cv # pylint: disable=E0401
import voluptuous as vol
from homeassistant import config_entries # pylint: disable=E0401
from homeassistant import config_entries # pylint: disable=E0401
from homeassistant.core import callback # pylint: disable=E0401

from custom_components.peaqhvac.configflow.config_flow_schemas import USER_SCHEMA, OPTIONAL_SCHEMA
from custom_components.peaqhvac.configflow.config_flow_validation import ConfigFlowValidation
from custom_components.peaqhvac.configflow.config_flow_schemas import (
USER_SCHEMA,
OPTIONAL_SCHEMA,
)
from custom_components.peaqhvac.configflow.config_flow_validation import (
ConfigFlowValidation,
)
from .const import DOMAIN

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -46,7 +52,10 @@ async def async_step_optional(self, user_input=None):
return self.async_create_entry(title=self.info["title"], data=self.data)

return self.async_show_form(
step_id="optional", data_schema=OPTIONAL_SCHEMA, errors=errors, last_step=True
step_id="optional",
data_schema=OPTIONAL_SCHEMA,
errors=errors,
last_step=True,
)


Expand All @@ -71,23 +80,38 @@ async def async_step_init(self, user_input=None):

_indoortemps = await self._get_existing_param("indoor_tempsensors", "")
_outdoortemps = await self._get_existing_param("outdoor_tempsensors", "")
_stopheatingtemp = await self._get_existing_param("outdoor_temp_stop_heating", 15)
_nonhours_waterboost = await self._get_existing_param("non_hours_water_boost", [])
_demandhours_waterboost = await self._get_existing_param("demand_hours_water_boost", [])
_stopheatingtemp = await self._get_existing_param(
"outdoor_temp_stop_heating", 15
)
_nonhours_waterboost = await self._get_existing_param(
"non_hours_water_boost", []
)
_demandhours_waterboost = await self._get_existing_param(
"demand_hours_water_boost", []
)
_lowdm = await self._get_existing_param("low_degree_minutes", "-600")
_verycoldtemp = await self._get_existing_param("very_cold_temp", "-12")

return self.async_show_form(
step_id="init",
last_step=True,
data_schema=vol.Schema({
vol.Optional("indoor_tempsensors", default=_indoortemps): cv.string,
vol.Optional("outdoor_tempsensors", default=_outdoortemps): cv.string,
vol.Optional("outdoor_temp_stop_heating", default=_stopheatingtemp): cv.positive_int,
vol.Optional("demand_hours_water_boost", default=_demandhours_waterboost): cv.multi_select(
list(range(0, 24))),
vol.Optional("non_hours_water_boost", default=_nonhours_waterboost): cv.multi_select(list(range(0, 24))),
vol.Optional("low_degree_minutes", default=_lowdm): cv.string,
vol.Optional("very_cold_temp", default=_verycoldtemp): cv.string,
})
)
data_schema=vol.Schema(
{
vol.Optional("indoor_tempsensors", default=_indoortemps): cv.string,
vol.Optional(
"outdoor_tempsensors", default=_outdoortemps
): cv.string,
vol.Optional(
"outdoor_temp_stop_heating", default=_stopheatingtemp
): cv.positive_int,
vol.Optional(
"demand_hours_water_boost", default=_demandhours_waterboost
): cv.multi_select(list(range(0, 24))),
vol.Optional(
"non_hours_water_boost", default=_nonhours_waterboost
): cv.multi_select(list(range(0, 24))),
vol.Optional("low_degree_minutes", default=_lowdm): cv.string,
vol.Optional("very_cold_temp", default=_verycoldtemp): cv.string,
}
),
)
21 changes: 13 additions & 8 deletions custom_components/peaqhvac/configflow/config_flow_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
}
)

OPTIONAL_SCHEMA = vol.Schema({
vol.Optional("outdoor_temp_stop_heating", default=15): cv.positive_int,
vol.Optional("non_hours_water_boost", default=[7, 11, 12, 15, 16, 17, 23]): cv.multi_select(list(range(0, 24))),
vol.Optional("demand_hours_water_boost", default=[]): cv.multi_select(list(range(0, 24))),
vol.Optional("low_degree_minutes", default="-600"): cv.string,
vol.Optional("very_cold_temp", default="-12"): cv.string,
})

OPTIONAL_SCHEMA = vol.Schema(
{
vol.Optional("outdoor_temp_stop_heating", default=15): cv.positive_int,
vol.Optional(
"non_hours_water_boost", default=[7, 11, 12, 15, 16, 17, 23]
): cv.multi_select(list(range(0, 24))),
vol.Optional("demand_hours_water_boost", default=[]): cv.multi_select(
list(range(0, 24))
),
vol.Optional("low_degree_minutes", default="-600"): cv.string,
vol.Optional("very_cold_temp", default="-12"): cv.string,
}
)
1 change: 1 addition & 0 deletions custom_components/peaqhvac/extensionmethods.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def _parse_to_type_bool(value) -> bool:
_LOGGER.error(msg)
return False


def dt_from_epoch(epoch: int) -> str:
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(epoch))

Expand Down
6 changes: 3 additions & 3 deletions custom_components/peaqhvac/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import logging

from homeassistant.components.number import NumberEntity # pylint: disable=E0401
from homeassistant.core import HomeAssistant # pylint: disable=E0401
from homeassistant.helpers.restore_state import RestoreEntity # pylint: disable=E0401
from homeassistant.components.number import NumberEntity # pylint: disable=E0401
from homeassistant.core import HomeAssistant # pylint: disable=E0401
from homeassistant.helpers.restore_state import RestoreEntity # pylint: disable=E0401
from peaqevcore.common.models.observer_types import ObserverTypes

from .const import DOMAIN
Expand Down
112 changes: 71 additions & 41 deletions custom_components/peaqhvac/sensor.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
"""Platform for sensor integration."""

import logging
from datetime import timedelta

from homeassistant.config_entries import ConfigEntry # pylint: disable=E0401
from homeassistant.core import HomeAssistant # pylint: disable=E0401

from .const import AVERAGESENSORS, DEMANDSENSORS, DOMAIN, NEXT_WATER_START, LATEST_WATER_BOOST, \
TRENDSENSOR_DM, TRENDSENSOR_OUTDOORS, TRENDSENSOR_INDOORS, TRENDSENSOR_WATERTEMP
from homeassistant.config_entries import ConfigEntry # pylint: disable=E0401
from homeassistant.core import HomeAssistant # pylint: disable=E0401

from .const import (
AVERAGESENSORS,
DEMANDSENSORS,
DOMAIN,
NEXT_WATER_START,
LATEST_WATER_BOOST,
TRENDSENSOR_DM,
TRENDSENSOR_OUTDOORS,
TRENDSENSOR_INDOORS,
TRENDSENSOR_WATERTEMP,
)
from .sensors.min_maxsensor import AverageSensor
from .sensors.money_data_sensor import PeaqMoneyDataSensor
from .sensors.offsetsensor import OffsetSensor
Expand All @@ -33,35 +43,38 @@ async def async_setup_entry(
async def _gather_sensors(hub, config) -> list:
TRENDSENSORS = [
{
"name": TRENDSENSOR_INDOORS,
"name": TRENDSENSOR_INDOORS,
"sensor": hub.sensors.temp_trend_indoors,
"icon": "mdi:home-thermometer",
"unit": "°C/h",
"icon": "mdi:home-thermometer",
"unit": "°C/h",
},
{
"name": TRENDSENSOR_OUTDOORS,
"name": TRENDSENSOR_OUTDOORS,
"sensor": hub.sensors.temp_trend_outdoors,
"icon": "mdi:sun-thermometer",
"unit": "°C/h",
"icon": "mdi:sun-thermometer",
"unit": "°C/h",
},
{
"name": TRENDSENSOR_DM,
"name": TRENDSENSOR_DM,
"sensor": hub.sensors.dm_trend,
"icon": "mdi:hvac",
"unit": "DM/h",
"icon": "mdi:hvac",
"unit": "DM/h",
"extra_attributes": {
"time_at_zero": (hub.sensors.dm_trend.predicted_time_at_value, 0)
}
},
},
{
"name": TRENDSENSOR_WATERTEMP,
"sensor": hub.hvac_service.water_heater.temp_trend,
"icon": "mdi:thermometer-water",
"unit": "°C/h",
"name": TRENDSENSOR_WATERTEMP,
"sensor": hub.hvac_service.water_heater.temp_trend,
"icon": "mdi:thermometer-water",
"unit": "°C/h",
"extra_attributes": {
"time_at_40": (hub.hvac_service.water_heater.temp_trend.predicted_time_at_value, 40)
}
}
"time_at_40": (
hub.hvac_service.water_heater.temp_trend.predicted_time_at_value,
40,
)
},
},
]

ret = []
Expand All @@ -70,32 +83,49 @@ async def _gather_sensors(hub, config) -> list:
for a in AVERAGESENSORS:
ret.append(AverageSensor(hub, config.entry_id, a))
for sensor in TRENDSENSORS:
ret.append(TrendSensor(
hub=hub,
entry_id=config.entry_id,
name=sensor["name"],
icon=sensor["icon"],
unit_of_measurement=sensor["unit"],
sensor=sensor["sensor"],
extra_attributes=sensor.get("extra_attributes", {})
))
ret.append(
TrendSensor(
hub=hub,
entry_id=config.entry_id,
name=sensor["name"],
icon=sensor["icon"],
unit_of_measurement=sensor["unit"],
sensor=sensor["sensor"],
extra_attributes=sensor.get("extra_attributes", {}),
)
)
for key in DEMANDSENSORS:
ret.append(PeaqSensor(hub, config.entry_id, key, DEMANDSENSORS[key]))

ret.append(PeaqSimpleSensor(hub, config.entry_id, "next water start", NEXT_WATER_START, "mdi:clock-start"))
ret.append(PeaqSimpleSensor(hub, config.entry_id, "latest water boost", LATEST_WATER_BOOST, "mdi:clock-end"))
ret.append(
PeaqSimpleSensor(
hub,
config.entry_id,
"next water start",
NEXT_WATER_START,
"mdi:clock-start",
)
)
ret.append(
PeaqSimpleSensor(
hub,
config.entry_id,
"latest water boost",
LATEST_WATER_BOOST,
"mdi:clock-end",
)
)

if not hub.options.misc_options.peaqev_discovered:
simplesensors = [("Average price this month", "average_month"),
("Average price 7 days", "average_weekly"),
("Average price 30 days", "average_30"),
("Average price 3 days", "average_three_days")]
simplesensors = [
("Average price this month", "average_month"),
("Average price 7 days", "average_weekly"),
("Average price 30 days", "average_30"),
("Average price 3 days", "average_three_days"),
]

for name, attr in simplesensors:
ret.append(
PeaqSimpleMoneySensor(
hub, config.entry_id, name, attr)
)
ret.append(PeaqSimpleMoneySensor(hub, config.entry_id, name, attr))
_LOGGER.debug(f"Setting up sensor for {name} with attr {attr}")

ret.append(PeaqMoneyDataSensor(hub, config.entry_id))
Expand Down
Loading

0 comments on commit 6de9c7b

Please sign in to comment.