Skip to content

Commit

Permalink
Merge 62e7dc0 into 4b21012
Browse files Browse the repository at this point in the history
  • Loading branch information
bramstroker committed Aug 28, 2022
2 parents 4b21012 + 62e7dc0 commit 57a1e40
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion custom_components/powercalc/helpers.py
Expand Up @@ -4,7 +4,7 @@
from homeassistant.helpers.template import Template


async def evaluate_power(power: Union[Template, Decimal]) -> Decimal:
async def evaluate_power(power: Union[Template, Decimal, float]) -> Decimal:
"""When power is a template render it."""

if isinstance(power, Template):
Expand Down
3 changes: 0 additions & 3 deletions custom_components/powercalc/sensors/utility_meter.py
Expand Up @@ -61,7 +61,6 @@ async def create_utility_meters(

for tariff in tariffs:
utility_meter = await create_utility_meter(
hass,
energy_sensor.entity_id,
entity_id,
name,
Expand All @@ -76,7 +75,6 @@ async def create_utility_meters(

else:
utility_meter = await create_utility_meter(
hass,
energy_sensor.entity_id,
entity_id,
name,
Expand Down Expand Up @@ -126,7 +124,6 @@ async def create_tariff_select(


async def create_utility_meter(
hass: HomeAssistant,
source_entity: str,
entity_id: str,
name: str,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/powercalc/strategy/fixed.py
Expand Up @@ -78,7 +78,7 @@ async def validate_config(self):
"fixed_states_power_only",
)

def get_entities_to_track(self) -> list[str, TrackTemplate]:
def get_entities_to_track(self) -> list[Union[str, TrackTemplate]]:
track_templates = []

if isinstance(self._power, Template):
Expand Down
12 changes: 7 additions & 5 deletions custom_components/powercalc/strategy/lut.py
Expand Up @@ -30,7 +30,6 @@
LutFileNotFound,
ModelNotSupported,
StrategyConfigurationError,
UnsupportedMode,
)
from ..power_profile.power_profile import PowerProfile
from .strategy_interface import PowerCalculationStrategyInterface
Expand Down Expand Up @@ -191,7 +190,7 @@ def lookup_power(self, lookup_table: dict, light_setting: LightSetting) -> float
return np.interp(brightness, brightness_range, power_range)

def lookup_power_for_brightness(
self, lut_value: Union(dict, int), light_setting: LightSetting
self, lut_value: Union[dict, int], light_setting: LightSetting
):
if light_setting.color_mode == COLOR_MODE_BRIGHTNESS:
return lut_value
Expand All @@ -201,13 +200,15 @@ def lookup_power_for_brightness(
sat_values = self.get_nearest(lut_value, light_setting.hue)
return self.get_nearest(sat_values, light_setting.saturation)

def get_nearest(self, dict: dict, search_key: int):
@staticmethod
def get_nearest(dict: dict, search_key: int):
return (
dict.get(search_key)
or dict[min(dict.keys(), key=lambda key: abs(key - search_key))]
)

def get_nearest_lower_brightness(self, dict: dict, search_key: int) -> int:
@staticmethod
def get_nearest_lower_brightness(dict: dict, search_key: int) -> int:
keys = dict.keys()
last_key = [*keys][-1]
if last_key < search_key:
Expand All @@ -217,7 +218,8 @@ def get_nearest_lower_brightness(self, dict: dict, search_key: int) -> int:
(k for k in dict.keys() if int(k) <= int(search_key)), default=[*keys][0]
)

def get_nearest_higher_brightness(self, dict: dict, search_key: int) -> int:
@staticmethod
def get_nearest_higher_brightness(dict: dict, search_key: int) -> int:
keys = dict.keys()
first_key = [*keys][0]
if first_key > search_key:
Expand Down
1 change: 1 addition & 0 deletions custom_components/powercalc/strategy/wled.py
Expand Up @@ -38,6 +38,7 @@ def __init__(
self._power_factor = config.get(CONF_POWER_FACTOR) or 0.9
self._light_entity = light_entity
self._standby_power = standby_power
self._estimated_current_entity: str | None = None

async def calculate(self, entity_state: State) -> Optional[Decimal]:
if entity_state.entity_id == self._light_entity.entity_id:
Expand Down

0 comments on commit 57a1e40

Please sign in to comment.