mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fix issue with group unique id when normalising bridge id (#30904)
This commit is contained in:
parent
1d41cf96ca
commit
7b29a498c6
@ -1,10 +1,11 @@
|
|||||||
"""Support for deCONZ devices."""
|
"""Support for deCONZ devices."""
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.config_entries import _UNDEF
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||||
|
|
||||||
from .config_flow import get_master_gateway
|
from .config_flow import get_master_gateway
|
||||||
from .const import CONF_MASTER_GATEWAY, DOMAIN
|
from .const import CONF_BRIDGE_ID, CONF_GROUP_ID_BASE, CONF_MASTER_GATEWAY, DOMAIN
|
||||||
from .gateway import DeconzGateway
|
from .gateway import DeconzGateway
|
||||||
from .services import async_setup_services, async_unload_services
|
from .services import async_setup_services, async_unload_services
|
||||||
|
|
||||||
@ -37,8 +38,14 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
|
|
||||||
# 0.104 introduced config entry unique id, this makes upgrading possible
|
# 0.104 introduced config entry unique id, this makes upgrading possible
|
||||||
if config_entry.unique_id is None:
|
if config_entry.unique_id is None:
|
||||||
|
|
||||||
|
new_data = _UNDEF
|
||||||
|
if CONF_BRIDGE_ID in config_entry.data:
|
||||||
|
new_data = dict(config_entry.data)
|
||||||
|
new_data[CONF_GROUP_ID_BASE] = config_entry.data[CONF_BRIDGE_ID]
|
||||||
|
|
||||||
hass.config_entries.async_update_entry(
|
hass.config_entries.async_update_entry(
|
||||||
config_entry, unique_id=gateway.api.config.bridgeid
|
config_entry, unique_id=gateway.api.config.bridgeid, data=new_data
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.data[DOMAIN][config_entry.unique_id] = gateway
|
hass.data[DOMAIN][config_entry.unique_id] = gateway
|
||||||
|
@ -21,7 +21,7 @@ from homeassistant.helpers import aiohttp_client
|
|||||||
from .const import (
|
from .const import (
|
||||||
CONF_ALLOW_CLIP_SENSOR,
|
CONF_ALLOW_CLIP_SENSOR,
|
||||||
CONF_ALLOW_DECONZ_GROUPS,
|
CONF_ALLOW_DECONZ_GROUPS,
|
||||||
CONF_BRIDGEID,
|
CONF_BRIDGE_ID,
|
||||||
DEFAULT_ALLOW_CLIP_SENSOR,
|
DEFAULT_ALLOW_CLIP_SENSOR,
|
||||||
DEFAULT_ALLOW_DECONZ_GROUPS,
|
DEFAULT_ALLOW_DECONZ_GROUPS,
|
||||||
DEFAULT_PORT,
|
DEFAULT_PORT,
|
||||||
@ -74,7 +74,7 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
for bridge in self.bridges:
|
for bridge in self.bridges:
|
||||||
if bridge[CONF_HOST] == user_input[CONF_HOST]:
|
if bridge[CONF_HOST] == user_input[CONF_HOST]:
|
||||||
self.bridge_id = bridge[CONF_BRIDGEID]
|
self.bridge_id = bridge[CONF_BRIDGE_ID]
|
||||||
self.deconz_config = {
|
self.deconz_config = {
|
||||||
CONF_HOST: bridge[CONF_HOST],
|
CONF_HOST: bridge[CONF_HOST],
|
||||||
CONF_PORT: bridge[CONF_PORT],
|
CONF_PORT: bridge[CONF_PORT],
|
||||||
|
@ -5,7 +5,8 @@ _LOGGER = logging.getLogger(__package__)
|
|||||||
|
|
||||||
DOMAIN = "deconz"
|
DOMAIN = "deconz"
|
||||||
|
|
||||||
CONF_BRIDGEID = "bridgeid"
|
CONF_BRIDGE_ID = "bridgeid"
|
||||||
|
CONF_GROUP_ID_BASE = "group_id_base"
|
||||||
|
|
||||||
DEFAULT_PORT = 80
|
DEFAULT_PORT = 80
|
||||||
DEFAULT_ALLOW_CLIP_SENSOR = False
|
DEFAULT_ALLOW_CLIP_SENSOR = False
|
||||||
|
@ -22,6 +22,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|||||||
import homeassistant.util.color as color_util
|
import homeassistant.util.color as color_util
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
|
CONF_GROUP_ID_BASE,
|
||||||
COVER_TYPES,
|
COVER_TYPES,
|
||||||
DOMAIN as DECONZ_DOMAIN,
|
DOMAIN as DECONZ_DOMAIN,
|
||||||
NEW_GROUP,
|
NEW_GROUP,
|
||||||
@ -205,7 +206,11 @@ class DeconzGroup(DeconzLight):
|
|||||||
"""Set up group and create an unique id."""
|
"""Set up group and create an unique id."""
|
||||||
super().__init__(device, gateway)
|
super().__init__(device, gateway)
|
||||||
|
|
||||||
self._unique_id = f"{self.gateway.api.config.bridgeid}-{self._device.deconz_id}"
|
group_id_base = self.gateway.config_entry.unique_id
|
||||||
|
if CONF_GROUP_ID_BASE in self.gateway.config_entry.data:
|
||||||
|
group_id_base = self.gateway.config_entry.data[CONF_GROUP_ID_BASE]
|
||||||
|
|
||||||
|
self._unique_id = f"{group_id_base}-{self._device.deconz_id}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
|
@ -6,7 +6,7 @@ from homeassistant.helpers import config_validation as cv
|
|||||||
from .config_flow import get_master_gateway
|
from .config_flow import get_master_gateway
|
||||||
from .const import (
|
from .const import (
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
CONF_BRIDGEID,
|
CONF_BRIDGE_ID,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
NEW_GROUP,
|
NEW_GROUP,
|
||||||
NEW_LIGHT,
|
NEW_LIGHT,
|
||||||
@ -27,14 +27,14 @@ SERVICE_CONFIGURE_DEVICE_SCHEMA = vol.All(
|
|||||||
vol.Optional(SERVICE_ENTITY): cv.entity_id,
|
vol.Optional(SERVICE_ENTITY): cv.entity_id,
|
||||||
vol.Optional(SERVICE_FIELD): cv.matches_regex("/.*"),
|
vol.Optional(SERVICE_FIELD): cv.matches_regex("/.*"),
|
||||||
vol.Required(SERVICE_DATA): dict,
|
vol.Required(SERVICE_DATA): dict,
|
||||||
vol.Optional(CONF_BRIDGEID): str,
|
vol.Optional(CONF_BRIDGE_ID): str,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
cv.has_at_least_one_key(SERVICE_ENTITY, SERVICE_FIELD),
|
cv.has_at_least_one_key(SERVICE_ENTITY, SERVICE_FIELD),
|
||||||
)
|
)
|
||||||
|
|
||||||
SERVICE_DEVICE_REFRESH = "device_refresh"
|
SERVICE_DEVICE_REFRESH = "device_refresh"
|
||||||
SERVICE_DEVICE_REFRESH_SCHEMA = vol.All(vol.Schema({vol.Optional(CONF_BRIDGEID): str}))
|
SERVICE_DEVICE_REFRESH_SCHEMA = vol.All(vol.Schema({vol.Optional(CONF_BRIDGE_ID): str}))
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_services(hass):
|
async def async_setup_services(hass):
|
||||||
@ -97,7 +97,7 @@ async def async_configure_service(hass, data):
|
|||||||
See Dresden Elektroniks REST API documentation for details:
|
See Dresden Elektroniks REST API documentation for details:
|
||||||
http://dresden-elektronik.github.io/deconz-rest-doc/rest/
|
http://dresden-elektronik.github.io/deconz-rest-doc/rest/
|
||||||
"""
|
"""
|
||||||
bridgeid = data.get(CONF_BRIDGEID)
|
bridgeid = data.get(CONF_BRIDGE_ID)
|
||||||
field = data.get(SERVICE_FIELD, "")
|
field = data.get(SERVICE_FIELD, "")
|
||||||
entity_id = data.get(SERVICE_ENTITY)
|
entity_id = data.get(SERVICE_ENTITY)
|
||||||
data = data[SERVICE_DATA]
|
data = data[SERVICE_DATA]
|
||||||
@ -119,8 +119,8 @@ async def async_configure_service(hass, data):
|
|||||||
async def async_refresh_devices_service(hass, data):
|
async def async_refresh_devices_service(hass, data):
|
||||||
"""Refresh available devices from deCONZ."""
|
"""Refresh available devices from deCONZ."""
|
||||||
gateway = get_master_gateway(hass)
|
gateway = get_master_gateway(hass)
|
||||||
if CONF_BRIDGEID in data:
|
if CONF_BRIDGE_ID in data:
|
||||||
gateway = hass.data[DOMAIN][data[CONF_BRIDGEID]]
|
gateway = hass.data[DOMAIN][data[CONF_BRIDGE_ID]]
|
||||||
|
|
||||||
groups = set(gateway.api.groups.keys())
|
groups = set(gateway.api.groups.keys())
|
||||||
lights = set(gateway.api.lights.keys())
|
lights = set(gateway.api.lights.keys())
|
||||||
|
@ -5,7 +5,7 @@ import pytest
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import deconz
|
from homeassistant.components import deconz
|
||||||
from homeassistant.components.deconz.const import CONF_BRIDGEID
|
from homeassistant.components.deconz.const import CONF_BRIDGE_ID
|
||||||
|
|
||||||
from .test_gateway import BRIDGEID, setup_deconz_integration
|
from .test_gateway import BRIDGEID, setup_deconz_integration
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ async def test_configure_service_with_field(hass):
|
|||||||
|
|
||||||
data = {
|
data = {
|
||||||
deconz.services.SERVICE_FIELD: "/light/2",
|
deconz.services.SERVICE_FIELD: "/light/2",
|
||||||
CONF_BRIDGEID: BRIDGEID,
|
CONF_BRIDGE_ID: BRIDGEID,
|
||||||
deconz.services.SERVICE_DATA: {"on": True, "attr1": 10, "attr2": 20},
|
deconz.services.SERVICE_DATA: {"on": True, "attr1": 10, "attr2": 20},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ async def test_service_refresh_devices(hass):
|
|||||||
"""Test that service can refresh devices."""
|
"""Test that service can refresh devices."""
|
||||||
gateway = await setup_deconz_integration(hass)
|
gateway = await setup_deconz_integration(hass)
|
||||||
|
|
||||||
data = {CONF_BRIDGEID: BRIDGEID}
|
data = {CONF_BRIDGE_ID: BRIDGEID}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"pydeconz.DeconzSession.request",
|
"pydeconz.DeconzSession.request",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user