mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Fix device refresh service can always add devices (#43950)
This commit is contained in:
parent
c5adaa1f5c
commit
bc83e30761
@ -121,9 +121,11 @@ class DeconzGateway:
|
|||||||
async_dispatcher_send(self.hass, self.signal_reachable, True)
|
async_dispatcher_send(self.hass, self.signal_reachable, True)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_device_callback(self, device_type, device=None) -> None:
|
def async_add_device_callback(
|
||||||
|
self, device_type, device=None, force: bool = False
|
||||||
|
) -> None:
|
||||||
"""Handle event of new device creation in deCONZ."""
|
"""Handle event of new device creation in deCONZ."""
|
||||||
if not self.option_allow_new_devices:
|
if not force and not self.option_allow_new_devices:
|
||||||
return
|
return
|
||||||
|
|
||||||
args = []
|
args = []
|
||||||
|
@ -146,10 +146,10 @@ async def async_refresh_devices_service(hass, data):
|
|||||||
await gateway.api.refresh_state()
|
await gateway.api.refresh_state()
|
||||||
gateway.ignore_state_updates = False
|
gateway.ignore_state_updates = False
|
||||||
|
|
||||||
gateway.async_add_device_callback(NEW_GROUP)
|
gateway.async_add_device_callback(NEW_GROUP, force=True)
|
||||||
gateway.async_add_device_callback(NEW_LIGHT)
|
gateway.async_add_device_callback(NEW_LIGHT, force=True)
|
||||||
gateway.async_add_device_callback(NEW_SCENE)
|
gateway.async_add_device_callback(NEW_SCENE, force=True)
|
||||||
gateway.async_add_device_callback(NEW_SENSOR)
|
gateway.async_add_device_callback(NEW_SENSOR, force=True)
|
||||||
|
|
||||||
|
|
||||||
async def async_remove_orphaned_entries_service(hass, data):
|
async def async_remove_orphaned_entries_service(hass, data):
|
||||||
|
@ -10,15 +10,19 @@ from homeassistant.components.binary_sensor import (
|
|||||||
from homeassistant.components.deconz.const import (
|
from homeassistant.components.deconz.const import (
|
||||||
CONF_ALLOW_CLIP_SENSOR,
|
CONF_ALLOW_CLIP_SENSOR,
|
||||||
CONF_ALLOW_NEW_DEVICES,
|
CONF_ALLOW_NEW_DEVICES,
|
||||||
|
CONF_MASTER_GATEWAY,
|
||||||
DOMAIN as DECONZ_DOMAIN,
|
DOMAIN as DECONZ_DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.components.deconz.gateway import get_gateway_from_config_entry
|
from homeassistant.components.deconz.gateway import get_gateway_from_config_entry
|
||||||
|
from homeassistant.components.deconz.services import SERVICE_DEVICE_REFRESH
|
||||||
from homeassistant.const import STATE_OFF, STATE_ON
|
from homeassistant.const import STATE_OFF, STATE_ON
|
||||||
from homeassistant.helpers.entity_registry import async_entries_for_config_entry
|
from homeassistant.helpers.entity_registry import async_entries_for_config_entry
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
|
from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
|
||||||
|
|
||||||
|
from tests.async_mock import patch
|
||||||
|
|
||||||
SENSORS = {
|
SENSORS = {
|
||||||
"1": {
|
"1": {
|
||||||
"id": "Presence sensor id",
|
"id": "Presence sensor id",
|
||||||
@ -172,7 +176,7 @@ async def test_add_new_binary_sensor_ignored(hass):
|
|||||||
"""Test that adding a new binary sensor is not allowed."""
|
"""Test that adding a new binary sensor is not allowed."""
|
||||||
config_entry = await setup_deconz_integration(
|
config_entry = await setup_deconz_integration(
|
||||||
hass,
|
hass,
|
||||||
options={CONF_ALLOW_NEW_DEVICES: False},
|
options={CONF_MASTER_GATEWAY: True, CONF_ALLOW_NEW_DEVICES: False},
|
||||||
)
|
)
|
||||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
gateway = get_gateway_from_config_entry(hass, config_entry)
|
||||||
assert len(hass.states.async_all()) == 0
|
assert len(hass.states.async_all()) == 0
|
||||||
@ -188,8 +192,23 @@ async def test_add_new_binary_sensor_ignored(hass):
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(hass.states.async_all()) == 0
|
assert len(hass.states.async_all()) == 0
|
||||||
|
assert not hass.states.get("binary_sensor.presence_sensor")
|
||||||
|
|
||||||
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
||||||
assert (
|
assert (
|
||||||
len(async_entries_for_config_entry(entity_registry, config_entry.entry_id)) == 0
|
len(async_entries_for_config_entry(entity_registry, config_entry.entry_id)) == 0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"pydeconz.DeconzSession.request",
|
||||||
|
return_value={
|
||||||
|
"groups": {},
|
||||||
|
"lights": {},
|
||||||
|
"sensors": {"1": deepcopy(SENSORS["1"])},
|
||||||
|
},
|
||||||
|
):
|
||||||
|
await hass.services.async_call(DECONZ_DOMAIN, SERVICE_DEVICE_REFRESH)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(hass.states.async_all()) == 1
|
||||||
|
assert hass.states.get("binary_sensor.presence_sensor")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user