Skip to content

Commit

Permalink
Merge branch 'master' into feat/sub-profile-select
Browse files Browse the repository at this point in the history
  • Loading branch information
bramstroker committed Oct 21, 2022
2 parents 52550e6 + 4dba3f9 commit 33b1037
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 29 deletions.
31 changes: 17 additions & 14 deletions custom_components/powercalc/config_flow.py
Expand Up @@ -558,21 +558,21 @@ async def save_options(self, user_input: dict[str, Any] | None = None) -> dict:
self.current_config.update(generic_options)

strategy = self.current_config.get(CONF_MODE)
if strategy:
strategy_options = _build_strategy_config(
strategy, self.source_entity_id, user_input
)

strategy_options = _build_strategy_config(
strategy, self.source_entity_id, user_input
)

if strategy != CalculationStrategy.LUT:
self.current_config.update({strategy: strategy_options})
if strategy != CalculationStrategy.LUT:
self.current_config.update({strategy: strategy_options})

strategy_object = await _create_strategy_object(
self.hass, strategy, self.current_config, self.source_entity
)
try:
await strategy_object.validate_config()
except StrategyConfigurationError as error:
return {"base": error.get_config_flow_translate_key()}
strategy_object = await _create_strategy_object(
self.hass, strategy, self.current_config, self.source_entity
)
try:
await strategy_object.validate_config()
except StrategyConfigurationError as error:
return {"base": error.get_config_flow_translate_key()}

if self.sensor_type == SensorType.GROUP:
self.current_config.update(user_input)
Expand All @@ -589,7 +589,10 @@ def build_options_schema(self) -> vol.Schema:
data_schema = {}
if self.sensor_type == SensorType.VIRTUAL_POWER:
strategy: str = self.current_config.get(CONF_MODE)
strategy_schema = _get_strategy_schema(strategy, self.source_entity_id)
if strategy:
strategy_schema = _get_strategy_schema(strategy, self.source_entity_id)
else:
strategy_schema = vol.Schema({})
data_schema = SCHEMA_POWER_OPTIONS.extend(strategy_schema.schema).extend(
SCHEMA_POWER_ADVANCED.schema
)
Expand Down
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions custom_components/powercalc/data/govee/H6072/model.json
@@ -0,0 +1,15 @@
{
"measure_description": "Measured with utils/measure script",
"measure_device": "Kasa KP115",
"measure_method": "script",
"measure_settings": {
"SAMPLE_COUNT": 2,
"SLEEP_TIME": 10,
"VERSION": "v0.26.1:docker"
},
"name": "Govee Lyra RGBICWW Corner Floor Lamp",
"standby_power": 1.78,
"supported_modes": [
"lut"
]
}
18 changes: 18 additions & 0 deletions custom_components/powercalc/data/innr/SP 120/model.json
@@ -0,0 +1,18 @@
{
"measure_description": "Manually measured, copied from SP 224.",
"measure_method": "manual",
"measure_device": "Shelly Plug S",
"name": "Innr Zigbee Smart Plug",
"standby_power": 0.41,
"sensor_config": {
"power_sensor_naming": "{} Device Power",
"energy_sensor_naming": "{} Device Energy"
},
"device_type": "smart_switch",
"supported_modes": [
"fixed"
],
"fixed_config": {
"power": 0.61
}
}
4 changes: 3 additions & 1 deletion custom_components/powercalc/data/signify/LCA006/model.json
Expand Up @@ -7,6 +7,8 @@
"supported_modes": [
"lut"
],
"aliases": []
"aliases": [
"9290024689"
]
}

3 changes: 3 additions & 0 deletions custom_components/powercalc/data/signify/LCE002/model.json
Expand Up @@ -4,6 +4,9 @@
"supported_modes": [
"lut"
],
"aliases": [
"929002294203"
],
"measure_method": "script",
"measure_device": "AVM FRITZ!DECT 200",
"measure_description": "Measured with own custom script"
Expand Down
7 changes: 5 additions & 2 deletions custom_components/powercalc/data/signify/LCF002/model.json
Expand Up @@ -6,5 +6,8 @@
],
"measure_device":"Gosund SP111 on Tasmota 9.5.0",
"measure_description":"Measure Script for Tasmota",
"measure_method":"script"
}
"measure_method":"script",
"aliases": [
"1742030P7"
]
}
3 changes: 3 additions & 0 deletions custom_components/powercalc/data/signify/LCT003/model.json
Expand Up @@ -3,6 +3,9 @@
"supported_modes": [
"lut"
],
"aliases": [
"8718696485880"
],
"measure_method": "script",
"measure_device": "Shelly plug S",
"measure_description": "Used script utils/measure_shelly.py from repository",
Expand Down
18 changes: 18 additions & 0 deletions custom_components/powercalc/data/signify/LOM007/model.json
@@ -0,0 +1,18 @@
{
"measure_description": "Manually measured. Copied from LOM001",
"measure_method": "manual",
"measure_device": "Shelly Plug S",
"name": "Hue smart plug LOM007",
"standby_power": 0.15,
"sensor_config": {
"power_sensor_naming": "{} Device Power",
"energy_sensor_naming": "{} Device Energy"
},
"device_type": "smart_switch",
"supported_modes": [
"fixed"
],
"fixed_config": {
"power": 0.85
}
}
Binary file not shown.
15 changes: 15 additions & 0 deletions custom_components/powercalc/data/signify/LTP002/model.json
@@ -0,0 +1,15 @@
{
"measure_description": "Measured with utils/measure script",
"measure_device": "Shelly Plug S",
"measure_method": "script",
"measure_settings": {
"SAMPLE_COUNT": 2,
"SLEEP_TIME": 3,
"VERSION": "v0.26.1:docker"
},
"name": "Hue ambiance pendant",
"standby_power": 0.59,
"supported_modes": [
"lut"
]
}
2 changes: 2 additions & 0 deletions custom_components/powercalc/strategy/factory.py
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Optional

from homeassistant.core import HomeAssistant
Expand Down
2 changes: 2 additions & 0 deletions custom_components/powercalc/strategy/strategy_interface.py
@@ -1,3 +1,5 @@
from __future__ import annotations

from decimal import Decimal

from homeassistant.core import State
Expand Down
16 changes: 10 additions & 6 deletions docs/supported_models.md
Expand Up @@ -3,7 +3,7 @@
- [Smart switches](#Smart-switches)

## Lights
#### 178 total
#### 180 total

| manufacturer | model id | name |calculation modes| aliases |
|--------------|-------------------------|---------------------------------------------------------------------------------|-----------------|-----------------------------------------------------------------------------------------------|
Expand All @@ -25,6 +25,7 @@
|gledopto |GL-B-001P |GL-B-001P |lut | |
|gledopto |GL-S-005Z |Gledopto 4W MR16 Dual White and Color 120° |lut | |
|gledopto |GL-S-007Z |Gledopto 5W GU10 Dual White And Color Spotlight |lut | |
|govee |H6072 |Govee Lyra RGBICWW Corner Floor Lamp |lut | |
|ikea |L1527 |FLOALT panel WS 30x30 |lut |FLOALT panel WS 30x30 |
|ikea |L1528 |FLOALT panel WS 30x90 |lut |FLOALT panel WS 30x90 |
|ikea |L1529 |FLOALT panel WS 60x60 |lut |FLOALT panel WS 60x60 |
Expand Down Expand Up @@ -99,20 +100,20 @@
|signify |1742930P7 |Hue Impress Outdoor Wall Light Small |lut | |
|signify |LCA001 |Hue White and Color Ambiance A19 E26/E27 (Gen 5) |lut |9290022166,929003053401,LCA005,9290022266A |
|signify |LCA003 |Hue White and Color Ambiance A19 E26 |lut | |
|signify |LCA006 |Hue White and Color Ambiance 1100 E27 with BT (9290024688) |lut | |
|signify |LCA006 |Hue White and Color Ambiance 1100 E27 with BT (9290024688) |lut | 9290024689|
|signify |LCA007 |Hue White and Color Ambiance A19 E26 1100lm |lut | 9290024687|
|signify |LCA008 |Hue White and Color Ambiance E27 1600lm |lut | 929002471601|
|signify |LCA009 |Hue color lamp (LCA009) |lut | |
|signify |LCB001 |Hue White and Color Ambiance BR30 Bluetooth |lut | |
|signify |LCD002 |Hue White and Color Ambiance Downlight 5/6 Inch |lut | |
|signify |LCE002 |Hue White and Color Ambiance E14 Candle w/ BT |lut | |
|signify |LCF002 |Hue Calla Outdoor Pedestal |lut | |
|signify |LCE002 |Hue White and Color Ambiance E14 Candle w/ BT |lut | 929002294203|
|signify |LCF002 |Hue Calla Outdoor Pedestal |lut |1742030P7 |
|signify |LCG002 |Hue White and Color Ambiance GU10 BT |lut | 929001953101|
|signify |LCL001 |Hue white and color ambiance LightStrip plus |lut | 8718699703424|
|signify |LCL003 |Hue Lily Outdoor Lightstrip |lut | |
|signify |LCS001 |Hue Lily Outdoor Spot Light RGBCCT |lut |1741430P7,1741530P7 |
|signify |LCT001 |Philips Hue White and Color Ambience (1 gen) |lut | |
|signify |LCT003 |Hue White and Color Ambiance Spot GU10 |lut | |
|signify |LCT003 |Hue White and Color Ambiance Spot GU10 |lut | 8718696485880|
|signify |LCT007 |Hue White and Color E27 Gen2 (2015) |lut | |
|signify |LCT010 |Hue White and Color Ambiance A19 E26 (Gen 3) |lut | |
|signify |LCT012 |Hue White and Color Ambiance Candle E12 |lut | |
Expand Down Expand Up @@ -141,6 +142,7 @@
|signify |LTE002 |Hue White Ambiance E14 w/ BT |lut | 9290022944|
|signify |LTG002 |Hue White Ambiance GU10 w/ BT |lut | 929001953301|
|signify |LTO001 |Hue G93 E27 Filament Globe Bulb |lut | |
|signify |LTP002 |Hue ambiance pendant |lut | |
|signify |LTP003 |Hue Fair Pendant |lut | |
|signify |LTP008 |Hue Being Pendant Light |lut | |
|signify |LTW001 |Hue White Ambiance A19 |lut | 8718696548738|
Expand Down Expand Up @@ -199,7 +201,7 @@
|lenovo |Smart Clock with Google Assistant|Lenovo Smart Clock with Google Assistant|linear | |

## Smart switches
#### 20 total
#### 22 total

|manufacturer| model id | name |calculation modes| aliases |
|------------|----------------|-----------------------------------------------------------------------------------|-----------------|----------|
Expand All @@ -211,6 +213,7 @@
|everspring |AN158 |Everspring AN158 |fixed | |
|fibaro |FGWP102 |Fibaro FGWP102 |fixed | |
|greenwave |GWPN1 |Greenwave GWPN1 |fixed | |
|innr |SP 120 |Innr Zigbee Smart Plug |fixed | |
|innr |SP 224 |Innr Zigbee Smart Plug |fixed | |
|neo-coolcam |NAS-WR01Z |Smart Power Plug |fixed | |
|nodon |Micro Smart Plug|NodOn Micro Smart Plug |fixed |MSP-3-1-X1|
Expand All @@ -219,6 +222,7 @@
|shelly |shelly plug s |Shelly Plug S |fixed | |
|signify |LOM001 |Hue smart plug LOM001 |fixed | |
|signify |LOM002 |Hue smart plug LOM002 |fixed | |
|signify |LOM007 |Hue smart plug LOM007 |fixed | |
|tp-link |HS100 |HS100 |fixed | |
|tp-link |HS110 |HS110 |fixed | |
|tp-link |KP115 |Kasa Smart WiFi Plug Slim with Energy Monitoring |fixed | |
Expand Down
4 changes: 1 addition & 3 deletions tests/common.py
Expand Up @@ -15,9 +15,7 @@
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.typing import ConfigType, StateType
from homeassistant.setup import async_setup_component
from pytest_homeassistant_custom_component.common import (
MockConfigEntry,
)
from pytest_homeassistant_custom_component.common import MockConfigEntry

import custom_components.test.light as test_light_platform
from custom_components.powercalc.const import (
Expand Down
40 changes: 37 additions & 3 deletions tests/test_config_flow.py
Expand Up @@ -646,7 +646,7 @@ async def test_lut_options_flow(hass: HomeAssistant):
)

assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert entry.data[CONF_CREATE_ENERGY_SENSOR] == False
assert not entry.data[CONF_CREATE_ENERGY_SENSOR]


async def test_group_options_flow(hass: HomeAssistant):
Expand Down Expand Up @@ -718,8 +718,42 @@ async def test_strategy_raises_unknown_error(hass: HomeAssistant):
assert result["type"] == data_entry_flow.FlowResultType.FORM


def _create_mock_entry(hass: HomeAssistant, entry_data: ConfigType) -> MockConfigEntry:
entry = MockConfigEntry(domain=DOMAIN, data=entry_data)
async def test_autodiscovered_option_flow(hass: HomeAssistant):
"""
Test that we can open an option flow for an auto discovered config entry
"""
entry = _create_mock_entry(
hass,
{
CONF_ENTITY_ID: "light.test",
CONF_NAME: "Test",
CONF_SENSOR_TYPE: SensorType.VIRTUAL_POWER,
CONF_MANUFACTURER: "signify",
CONF_MODEL: "LCT010",
},
config_entries.SOURCE_INTEGRATION_DISCOVERY,
)

result = await _initialize_options_flow(hass, entry)
assert result["type"] == data_entry_flow.FlowResultType.FORM

user_input = {CONF_CREATE_ENERGY_SENSOR: False}

result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input=user_input,
)

assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert not entry.data[CONF_CREATE_ENERGY_SENSOR]


def _create_mock_entry(
hass: HomeAssistant,
entry_data: ConfigType,
source: str = config_entries.SOURCE_USER,
) -> MockConfigEntry:
entry = MockConfigEntry(domain=DOMAIN, data=entry_data, source=source)
entry.add_to_hass(hass)

assert not entry.options
Expand Down

0 comments on commit 33b1037

Please sign in to comment.