Add vera config entries support (#29880)
* Adding vera config entries support. * Fixing lint error. * Applying minimal changes necessary to get config entries working. * Addressing PR feedback by further reducing the scope of the change. * Addressing PR feedback. * Fixing pyvera import to make it easier to patch. Addressing PR feedback regarding creation of controller and scheduling of async config flow actions. * Updating code owners file. * Small fixes. * Adding a user config flow step. * Adding optional configs for user config flow. * Updating strings to be more clear to the user. * Adding options flow. Fixing some PR feedback. * Better handling of options. PR feedback changes. * Using config registry to update config options. * Better managing config from file or config from UI Disabling config through UI if config is provided from a file. More tests to account for these adjustments. * Address PR feedback. * Fixing test, merging with master. * Disabling all Vera UI for configs managed by configuration.yml. Adding more tests. * Updating config based on unique_id. Addressing additional PR feedback. * Rebasing off dev. Addressing feedback. * Addressing PR feedback.
This commit is contained in:
1 parent
aef06a3544
commit
ae22b5187a
28 files changed
+876
-294
No files matched your search
@@ -2,21 +2,12 @@
|
||||
from typing import Any, Callable, Tuple
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from pyvera import (
|
||||
CATEGORY_HUMIDITY_SENSOR,
|
||||
CATEGORY_LIGHT_SENSOR,
|
||||
CATEGORY_POWER_METER,
|
||||
CATEGORY_SCENE_CONTROLLER,
|
||||
CATEGORY_TEMPERATURE_SENSOR,
|
||||
CATEGORY_UV_SENSOR,
|
||||
VeraController,
|
||||
VeraSensor,
|
||||
)
|
||||
import pyvera as pv
|
||||
|
||||
from homeassistant.const import UNIT_PERCENTAGE
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import ComponentFactory
|
||||
from .common import ComponentFactory, new_simple_controller_config
|
||||
|
||||
|
||||
async def run_sensor_test(
|
||||
@@ -26,10 +17,10 @@ async def run_sensor_test(
|
||||
class_property: str,
|
||||
assert_states: Tuple[Tuple[Any, Any]],
|
||||
assert_unit_of_measurement: str = None,
|
||||
setup_callback: Callable[[VeraController], None] = None,
|
||||
setup_callback: Callable[[pv.VeraController], None] = None,
|
||||
) -> None:
|
||||
"""Test generic sensor."""
|
||||
vera_device = MagicMock(spec=VeraSensor) # type: VeraSensor
|
||||
vera_device = MagicMock(spec=pv.VeraSensor) # type: pv.VeraSensor
|
||||
vera_device.device_id = 1
|
||||
vera_device.name = "dev1"
|
||||
vera_device.category = category
|
||||
@@ -37,10 +28,12 @@ async def run_sensor_test(
|
||||
entity_id = "sensor.dev1_1"
|
||||
|
||||
component_data = await vera_component_factory.configure_component(
|
||||
hass=hass, devices=(vera_device,), setup_callback=setup_callback
|
||||
hass=hass,
|
||||
controller_config=new_simple_controller_config(
|
||||
devices=(vera_device,), setup_callback=setup_callback
|
||||
),
|
||||
)
|
||||
controller = component_data.controller
|
||||
update_callback = controller.register.call_args_list[0][0][1]
|
||||
update_callback = component_data.controller_data.update_callback
|
||||
|
||||
for (initial_value, state_value) in assert_states:
|
||||
setattr(vera_device, class_property, initial_value)
|
||||
@@ -57,13 +50,13 @@ async def test_temperature_sensor_f(
|
||||
) -> None:
|
||||
"""Test function."""
|
||||
|
||||
def setup_callback(controller: VeraController, hass_config: dict) -> None:
|
||||
def setup_callback(controller: pv.VeraController) -> None:
|
||||
controller.temperature_units = "F"
|
||||
|
||||
await run_sensor_test(
|
||||
hass=hass,
|
||||
vera_component_factory=vera_component_factory,
|
||||
category=CATEGORY_TEMPERATURE_SENSOR,
|
||||
category=pv.CATEGORY_TEMPERATURE_SENSOR,
|
||||
class_property="temperature",
|
||||
assert_states=(("33", "1"), ("44", "7")),
|
||||
setup_callback=setup_callback,
|
||||
@@ -77,7 +70,7 @@ async def test_temperature_sensor_c(
|
||||
await run_sensor_test(
|
||||
hass=hass,
|
||||
vera_component_factory=vera_component_factory,
|
||||
category=CATEGORY_TEMPERATURE_SENSOR,
|
||||
category=pv.CATEGORY_TEMPERATURE_SENSOR,
|
||||
class_property="temperature",
|
||||
assert_states=(("33", "33"), ("44", "44")),
|
||||
)
|
||||
@@ -90,7 +83,7 @@ async def test_light_sensor(
|
||||
await run_sensor_test(
|
||||
hass=hass,
|
||||
vera_component_factory=vera_component_factory,
|
||||
category=CATEGORY_LIGHT_SENSOR,
|
||||
category=pv.CATEGORY_LIGHT_SENSOR,
|
||||
class_property="light",
|
||||
assert_states=(("12", "12"), ("13", "13")),
|
||||
assert_unit_of_measurement="lx",
|
||||
@@ -104,7 +97,7 @@ async def test_uv_sensor(
|
||||
await run_sensor_test(
|
||||
hass=hass,
|
||||
vera_component_factory=vera_component_factory,
|
||||
category=CATEGORY_UV_SENSOR,
|
||||
category=pv.CATEGORY_UV_SENSOR,
|
||||
class_property="light",
|
||||
assert_states=(("12", "12"), ("13", "13")),
|
||||
assert_unit_of_measurement="level",
|
||||
@@ -118,7 +111,7 @@ async def test_humidity_sensor(
|
||||
await run_sensor_test(
|
||||
hass=hass,
|
||||
vera_component_factory=vera_component_factory,
|
||||
category=CATEGORY_HUMIDITY_SENSOR,
|
||||
category=pv.CATEGORY_HUMIDITY_SENSOR,
|
||||
class_property="humidity",
|
||||
assert_states=(("12", "12"), ("13", "13")),
|
||||
assert_unit_of_measurement=UNIT_PERCENTAGE,
|
||||
@@ -132,7 +125,7 @@ async def test_power_meter_sensor(
|
||||
await run_sensor_test(
|
||||
hass=hass,
|
||||
vera_component_factory=vera_component_factory,
|
||||
category=CATEGORY_POWER_METER,
|
||||
category=pv.CATEGORY_POWER_METER,
|
||||
class_property="power",
|
||||
assert_states=(("12", "12"), ("13", "13")),
|
||||
assert_unit_of_measurement="watts",
|
||||
@@ -144,7 +137,7 @@ async def test_trippable_sensor(
|
||||
) -> None:
|
||||
"""Test function."""
|
||||
|
||||
def setup_callback(controller: VeraController, hass_config: dict) -> None:
|
||||
def setup_callback(controller: pv.VeraController) -> None:
|
||||
controller.get_devices()[0].is_trippable = True
|
||||
|
||||
await run_sensor_test(
|
||||
@@ -162,7 +155,7 @@ async def test_unknown_sensor(
|
||||
) -> None:
|
||||
"""Test function."""
|
||||
|
||||
def setup_callback(controller: VeraController, hass_config: dict) -> None:
|
||||
def setup_callback(controller: pv.VeraController) -> None:
|
||||
controller.get_devices()[0].is_trippable = False
|
||||
|
||||
await run_sensor_test(
|
||||
@@ -179,21 +172,21 @@ async def test_scene_controller_sensor(
|
||||
hass: HomeAssistant, vera_component_factory: ComponentFactory
|
||||
) -> None:
|
||||
"""Test function."""
|
||||
vera_device = MagicMock(spec=VeraSensor) # type: VeraSensor
|
||||
vera_device = MagicMock(spec=pv.VeraSensor) # type: pv.VeraSensor
|
||||
vera_device.device_id = 1
|
||||
vera_device.name = "dev1"
|
||||
vera_device.category = CATEGORY_SCENE_CONTROLLER
|
||||
vera_device.category = pv.CATEGORY_SCENE_CONTROLLER
|
||||
vera_device.get_last_scene_id = MagicMock(return_value="id0")
|
||||
vera_device.get_last_scene_time = MagicMock(return_value="0000")
|
||||
entity_id = "sensor.dev1_1"
|
||||
|
||||
component_data = await vera_component_factory.configure_component(
|
||||
hass=hass, devices=(vera_device,)
|
||||
hass=hass,
|
||||
controller_config=new_simple_controller_config(devices=(vera_device,)),
|
||||
)
|
||||
controller = component_data.controller
|
||||
update_callback = controller.register.call_args_list[0][0][1]
|
||||
update_callback = component_data.controller_data.update_callback
|
||||
|
||||
vera_device.get_last_scene_time = "1111"
|
||||
vera_device.get_last_scene_time.return_value = "1111"
|
||||
update_callback(vera_device)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(entity_id).state == "id0"
|
||||
Reference in new issue
Block a user