Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bramstroker/homeassistant-huepowe…
Browse files Browse the repository at this point in the history
…r into master
  • Loading branch information
bramstroker committed Jun 29, 2021
2 parents f045c02 + ec4df59 commit 1d76374
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
11 changes: 7 additions & 4 deletions custom_components/powercalc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from __future__ import annotations

from typing import Optional
import logging
from typing import Optional

from homeassistant.helpers.typing import HomeAssistantType

Expand Down Expand Up @@ -46,7 +46,11 @@ def __init__(self, hass: HomeAssistantType) -> None:
self._lut_registry = LutRegistry()

def create(
self, config: dict, mode: str, light_model: Optional[LightModel], entity_domain: str
self,
config: dict,
mode: str,
light_model: Optional[LightModel],
entity_domain: str,
) -> PowerCalculationStrategyInterface:
"""Create instance of calculation strategy based on configuration"""
if mode == MODE_LINEAR:
Expand Down Expand Up @@ -96,8 +100,7 @@ def _create_fixed(self, config: dict, light_model: LightModel) -> FixedStrategy:
fixed_config = {CONF_POWER: config.get(CONF_WATT)}

return FixedStrategy(
fixed_config.get(CONF_POWER),
fixed_config.get(CONF_STATES_POWER)
fixed_config.get(CONF_POWER), fixed_config.get(CONF_STATES_POWER)
)

def _create_lut(self, light_model: LightModel) -> LutStrategy:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/powercalc/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
)
from .errors import ModelNotSupported, StrategyConfigurationError, UnsupportedMode
from .light_model import LightModel
from .strategy_interface import PowerCalculationStrategyInterface
from .strategy_fixed import CONFIG_SCHEMA as FIXED_SCHEMA
from .strategy_interface import PowerCalculationStrategyInterface
from .strategy_linear import CONFIG_SCHEMA as LINEAR_SCHEMA

_LOGGER = logging.getLogger(__name__)
Expand Down
12 changes: 4 additions & 8 deletions custom_components/powercalc/strategy_fixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,19 @@
import voluptuous as vol
from homeassistant.core import State

from .const import (
CONF_POWER,
CONF_STATES_POWER
)
from .const import CONF_POWER, CONF_STATES_POWER
from .strategy_interface import PowerCalculationStrategyInterface

CONFIG_SCHEMA = vol.Schema(
{
vol.Optional(CONF_POWER): vol.Coerce(float),
vol.Optional(CONF_STATES_POWER, default={}): vol.Schema(
{
cv.string: vol.Coerce(float)
}
)
{cv.string: vol.Coerce(float)}
),
}
)


class FixedStrategy(PowerCalculationStrategyInterface):
def __init__(
self, power: Optional[float], per_state_power: Optional[dict[str, float]]
Expand Down
6 changes: 1 addition & 5 deletions custom_components/powercalc/strategy_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
from homeassistant.core import State
from homeassistant.helpers.config_validation import entity_domain

from .const import (
CONF_CALIBRATE,
CONF_MAX_POWER,
CONF_MIN_POWER
)
from .const import CONF_CALIBRATE, CONF_MAX_POWER, CONF_MIN_POWER
from .errors import StrategyConfigurationError
from .strategy_interface import PowerCalculationStrategyInterface

Expand Down

0 comments on commit 1d76374

Please sign in to comment.