Skip to content

Commit

Permalink
⬆️ Update Powercalc integration to v1.9.9
Browse files Browse the repository at this point in the history
  • Loading branch information
klaasnicolaas committed Dec 6, 2023
1 parent 6712da5 commit d530ab9
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 16 deletions.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"measure_description": "Measured with utils/measure script",
"measure_device": "TP-Link Tapo P110",
"measure_method": "script",
"measure_settings": {
"SAMPLE_COUNT": 2,
"SLEEP_TIME": 3,
"VERSION": "v1.9.8:docker"
},
"name": "Smart Nue ZigBee 9W RGBW downlight",
"standby_power": 0.64,
"calculation_strategy": "lut"
}
Binary file not shown.
16 changes: 16 additions & 0 deletions custom_components/powercalc/data/ikea/LED2107C4/model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"calculation_strategy": "lut",
"measure_description": "Measured with utils/measure script; 2.99 Watts dummy load",
"measure_device": "Shelly Plus Plug S",
"measure_method": "script",
"measure_settings": {
"SAMPLE_COUNT": 5,
"SLEEP_TIME": 3,
"VERSION": "v1.9.5:docker"
},
"name": "TRADFRI bulb E14 WS candle 470lm",
"standby_power": 0.15,
"aliases": [
"TRADFRI bulb E14 WS candle 470lm"
]
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"neo-coolcam": ["smart_switch"], "sonoff": ["light", "smart_switch"], "blitzwolf": ["smart_switch"], "zipato": ["light"], "lifx": ["light"], "paulmann licht": ["light"], "malmbergs": ["light"], "nous": ["smart_switch"], "fibaro": ["smart_switch"], "qubino": ["smart_switch"], "trust": ["light"], "apple": ["smart_speaker"], "lexman": ["light"], "3a smarthome": ["light"], "avm": ["smart_switch", "light", "network"], "gledopto": ["light"], "ynoa": ["light"], "bose": ["smart_speaker"], "mueller-licht": ["light"], "cree": ["light"], "elgato": ["light"], "genio": ["light"], "oz smart things": ["light"], "ge": ["light"], "athom": ["light"], "zengge": ["light"], "shelly": ["smart_switch"], "nodon": ["smart_switch"], "eufy": ["camera"], "greenwave": ["smart_switch"], "lenovo": ["smart_speaker"], "osram": ["light", "smart_switch"], "meross": ["light"], "lidl": ["light"], "belkin": ["light"], "signify": ["light", "smart_switch"], "innr": ["light", "smart_switch"], "ledvance": ["light"], "zemismart": ["light"], "melitec": ["light"], "aqara": ["light"], "yeelight": ["light"], "google": ["smart_speaker"], "denon": ["smart_speaker"], "sonos": ["smart_speaker"], "harman kardon": ["smart_speaker"], "govee": ["light"], "tp-link": ["smart_switch", "light"], "arlec": ["smart_switch", "light"], "linkind": ["light"], "ajax online": ["light"], "bosch": ["smart_switch"], "rye": ["light"], "ikea": ["light", "smart_switch"], "teckin": ["light"], "tuya": ["smart_switch", "light"], "amazon": ["smart_speaker"], "wiz": ["light"], "anko": ["light"], "everspring": ["smart_switch"]}
{"neo-coolcam": ["smart_switch"], "zemismart": ["light"], "zengge": ["light"], "qubino": ["smart_switch"], "elgato": ["light"], "3a smarthome": ["light"], "sonoff": ["smart_switch", "light"], "rye": ["light"], "signify": ["light", "smart_switch"], "apple": ["smart_speaker"], "everspring": ["smart_switch"], "greenwave": ["smart_switch"], "ge": ["light"], "mueller-licht": ["light"], "oz smart things": ["light"], "aqara": ["light"], "ledvance": ["light"], "denon": ["smart_speaker"], "govee": ["light"], "lenovo": ["smart_speaker"], "genio": ["light"], "meross": ["light"], "ikea": ["light", "smart_switch"], "athom": ["light"], "melitec": ["light"], "sonos": ["smart_speaker"], "ajax online": ["light"], "yeelight": ["light"], "paulmann licht": ["light"], "arlec": ["smart_switch", "light"], "lidl": ["light"], "zipato": ["light"], "trust": ["light"], "fibaro": ["smart_switch"], "tp-link": ["light", "smart_switch"], "lifx": ["light"], "harman kardon": ["smart_speaker"], "blitzwolf": ["smart_switch"], "lexman": ["light"], "belkin": ["light"], "ynoa": ["light"], "google": ["smart_speaker"], "teckin": ["light"], "anko": ["light"], "linkind": ["light"], "bosch": ["smart_switch"], "innr": ["light", "smart_switch"], "amazon": ["smart_speaker"], "nous": ["smart_switch"], "cree": ["light"], "tuya": ["light", "smart_switch"], "wiz": ["light"], "osram": ["light", "smart_switch"], "avm": ["smart_switch", "light", "network"], "gledopto": ["light"], "shelly": ["smart_switch"], "nodon": ["smart_switch"], "eufy": ["camera"], "malmbergs": ["light"], "bose": ["smart_speaker"]}
Binary file not shown.
13 changes: 13 additions & 0 deletions custom_components/powercalc/data/osram/AB401130055/model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"calculation_strategy": "lut",
"measure_description": "Measured with utils/measure script",
"measure_device": "Shelly Plus 1PM",
"measure_method": "script",
"measure_settings": {
"SAMPLE_COUNT": 2,
"SLEEP_TIME": 3,
"VERSION": "v1.9.8:docker"
},
"name": "LIGHTIFY Surface Light LED Tunable White",
"standby_power": 0.4
}
Binary file not shown.
Binary file not shown.
14 changes: 14 additions & 0 deletions custom_components/powercalc/data/signify/1745630P7/model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"calculation_strategy": "lut",
"measure_description": "Measured with utils/measure script",
"measure_device": "Shelly Plug S",
"measure_method": "script",
"measure_settings": {
"SAMPLE_COUNT": 2,
"SLEEP_TIME": 3,
"VERSION": "v1.9.6:docker"
},
"name": "1745630P7",
"standby_power": 0.27,
"device_type": "light"
}
2 changes: 1 addition & 1 deletion custom_components/powercalc/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
"requirements": [
"numpy>=1.21.1"
],
"version": "v1.9.7"
"version": "v1.9.9"
}
10 changes: 5 additions & 5 deletions custom_components/powercalc/sensors/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,14 +496,14 @@ async def async_added_to_hass(self) -> None:
)
except DecimalException as err:
_LOGGER.warning(
"%s: Could not restore last state: %s", self.entity_id, err,
"%s: Could not restore last state: %s",
self.entity_id,
err,
)

self._prev_state_store = await PreviousStateStore.async_get_instance(self.hass)
state_listener = Throttle(timedelta(seconds=30))(state_listener)

# throttle group updates to only once each X seconds, to prevent overloading the state machine
throttle_secs = 30 if isinstance(self, GroupedEnergySensor) else 5
state_listener = Throttle(timedelta(seconds=throttle_secs))(state_listener)
self._prev_state_store = await PreviousStateStore.async_get_instance(self.hass)

self.async_on_remove(
async_track_state_change_event(
Expand Down
32 changes: 23 additions & 9 deletions custom_components/powercalc/sensors/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ def __init__(
) -> None:
"""Initialize the sensor."""
self._calculation_strategy = calculation_strategy
self._calculation_enabled_condition: Template | None = None
self._source_entity = source_entity
self._attr_name = name
self._power: Decimal | None = None
Expand Down Expand Up @@ -380,6 +381,7 @@ async def async_added_to_hass(self) -> None:
await super().async_added_to_hass()
await self.ensure_strategy_instance()
assert self._strategy_instance is not None
self.init_calculation_enabled_condition()

async def appliance_state_listener(event: Event) -> None:
"""Handle for state changes for dependent sensors."""
Expand Down Expand Up @@ -444,6 +446,10 @@ async def initial_update(hass: HomeAssistant) -> None:
if isinstance(self._standby_power, Template):
self._standby_power.hass = self.hass
track_templates.append(TrackTemplate(self._standby_power, None, None))
if self._calculation_enabled_condition:
track_templates.append(
TrackTemplate(self._calculation_enabled_condition, None, None)
)
if track_templates:
async_track_template_result(
self.hass,
Expand All @@ -463,6 +469,21 @@ def async_update(event_time: datetime | None = None) -> None:

async_track_time_interval(self.hass, async_update, self._update_frequency)

def init_calculation_enabled_condition(self) -> None:
if CONF_CALCULATION_ENABLED_CONDITION not in self._sensor_config:
return

template = self._sensor_config.get(CONF_CALCULATION_ENABLED_CONDITION)
if isinstance(template, str):
template = template.replace("[[entity]]", self.source_entity)
template = Template(template)

if not isinstance(template, Template):
_LOGGER.error("Invalid calculation_enabled_condition: %s", template)
return

self._calculation_enabled_condition = template

async def _handle_source_entity_state_change(
self,
trigger_entity_id: str,
Expand Down Expand Up @@ -620,17 +641,10 @@ def _update_sleep_power(*_: Any) -> None: # noqa: ANN401
return standby_power

async def is_calculation_enabled(self) -> bool:
if CONF_CALCULATION_ENABLED_CONDITION not in self._sensor_config:
template = self._calculation_enabled_condition
if not template:
return True

template = self._sensor_config.get(CONF_CALCULATION_ENABLED_CONDITION)
if isinstance(template, str):
template = template.replace("[[entity]]", self.source_entity)
template = Template(template)

if not isinstance(template, Template):
return True # pragma: no cover

template.hass = self.hass
return bool(template.async_render())

Expand Down
4 changes: 4 additions & 0 deletions custom_components/powercalc/translations/sk.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,14 @@
"energy_integration_method": "Metóda energetickej integrácie",
"ignore_unavailable_state": "Ignorovať nedostupný stav",
"multiply_factor": "Násobný faktor",
"multiply_factor_standby": "Pohotovostný režim s násobným faktorom",
"unavailable_power": "Nedostupné napájanie"
},
"data_description": {
"calculation_enabled_condition": "Konfigurovaná stratégia výpočtu výkonu sa vykoná len vtedy, keď sa táto šablóna vyhodnotí ako pravda alebo 1, inak snímač výkonu zobrazí 0",
"ignore_unavailable_state": "Toto nastavenie prepnite, ak chcete, aby snímač výkonu zostal dostupný, aj keď zdrojová entita nie je k dispozícii",
"multiply_factor": "Vynásobí vypočítaný výkon týmto pomerom. Môže byť užitočné pre ľahké skupiny",
"multiply_factor_standby": "Či sa má použiť multiplikačný faktor aj na výkon v pohotovostnom režime",
"unavailable_power": "Výkon vo W na zaznamenanie, keď má zdrojová entita nedostupný stav"
},
"description": "Možnosti uvedené nižšie sú pre pokročilú konfiguráciu powercalc. Väčšina používateľov to nebude používať, takže ich môžete preskočiť",
Expand Down Expand Up @@ -240,6 +242,7 @@
"max_power": "Max výkon",
"min_power": "Min výkon",
"multiply_factor": "Násobný faktor",
"multiply_factor_standby": "Pohotovostný režim s násobným faktorom",
"name": "Názov",
"on_time": "V čase",
"playbooks": "Playbooky",
Expand All @@ -266,6 +269,7 @@
"group_power_entities": "Vrátane prídavných výkonových snímačov (W) z vašej inštalácie HA",
"ignore_unavailable_state": "Toto nastavenie prepnite, ak chcete, aby snímač výkonu zostal dostupný, aj keď zdrojová entita nie je k dispozícii",
"multiply_factor": "Vynásobí vypočítaný výkon týmto pomerom. Môže byť užitočné pre ľahké skupiny",
"multiply_factor_standby": "Či sa má použiť multiplikačný faktor aj na výkon v pohotovostnom režime",
"playbooks": "Do každého riadku zadajte playbook. Príklad\n\nprogram1: washing_machine/program1.csv",
"power_template": "Šablóna sa vyhodnotí, aby sa získala hodnota výkonu vo W",
"repeat": "Prepínač, keď chcete pokračovať v opakovaní príručky po jej dokončení",
Expand Down

0 comments on commit d530ab9

Please sign in to comment.