mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Additional fix for rainbird unique id (#101599)
Additiona fix for rainbird unique id
This commit is contained in:
parent
da3e36aa3b
commit
8c2a2e5c37
@ -48,7 +48,7 @@ class RainBirdSensor(CoordinatorEntity[RainbirdUpdateCoordinator], BinarySensorE
|
|||||||
"""Initialize the Rain Bird sensor."""
|
"""Initialize the Rain Bird sensor."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
if coordinator.unique_id:
|
if coordinator.unique_id is not None:
|
||||||
self._attr_unique_id = f"{coordinator.unique_id}-{description.key}"
|
self._attr_unique_id = f"{coordinator.unique_id}-{description.key}"
|
||||||
self._attr_device_info = coordinator.device_info
|
self._attr_device_info = coordinator.device_info
|
||||||
else:
|
else:
|
||||||
|
@ -84,7 +84,7 @@ class RainbirdUpdateCoordinator(DataUpdateCoordinator[RainbirdDeviceState]):
|
|||||||
@property
|
@property
|
||||||
def device_info(self) -> DeviceInfo | None:
|
def device_info(self) -> DeviceInfo | None:
|
||||||
"""Return information about the device."""
|
"""Return information about the device."""
|
||||||
if not self._unique_id:
|
if self._unique_id is None:
|
||||||
return None
|
return None
|
||||||
return DeviceInfo(
|
return DeviceInfo(
|
||||||
name=self.device_name,
|
name=self.device_name,
|
||||||
|
@ -7,7 +7,7 @@ from homeassistant.const import Platform
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from .conftest import RAIN_SENSOR_OFF, RAIN_SENSOR_ON, ComponentSetup
|
from .conftest import RAIN_SENSOR_OFF, RAIN_SENSOR_ON, SERIAL_NUMBER, ComponentSetup
|
||||||
|
|
||||||
from tests.test_util.aiohttp import AiohttpClientMockResponse
|
from tests.test_util.aiohttp import AiohttpClientMockResponse
|
||||||
|
|
||||||
@ -41,11 +41,38 @@ async def test_rainsensor(
|
|||||||
"icon": "mdi:water",
|
"icon": "mdi:water",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("config_entry_unique_id", "entity_unique_id"),
|
||||||
|
[
|
||||||
|
(SERIAL_NUMBER, "1263613994342-rainsensor"),
|
||||||
|
# Some existing config entries may have a "0" serial number but preserve
|
||||||
|
# their unique id
|
||||||
|
(0, "0-rainsensor"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_unique_id(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
setup_integration: ComponentSetup,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
entity_unique_id: str,
|
||||||
|
) -> None:
|
||||||
|
"""Test rainsensor binary sensor."""
|
||||||
|
|
||||||
|
assert await setup_integration()
|
||||||
|
|
||||||
|
rainsensor = hass.states.get("binary_sensor.rain_bird_controller_rainsensor")
|
||||||
|
assert rainsensor is not None
|
||||||
|
assert rainsensor.attributes == {
|
||||||
|
"friendly_name": "Rain Bird Controller Rainsensor",
|
||||||
|
"icon": "mdi:water",
|
||||||
|
}
|
||||||
|
|
||||||
entity_entry = entity_registry.async_get(
|
entity_entry = entity_registry.async_get(
|
||||||
"binary_sensor.rain_bird_controller_rainsensor"
|
"binary_sensor.rain_bird_controller_rainsensor"
|
||||||
)
|
)
|
||||||
assert entity_entry
|
assert entity_entry
|
||||||
assert entity_entry.unique_id == "1263613994342-rainsensor"
|
assert entity_entry.unique_id == entity_unique_id
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
@ -63,6 +63,36 @@ async def test_number_values(
|
|||||||
assert entity_entry.unique_id == "1263613994342-rain-delay"
|
assert entity_entry.unique_id == "1263613994342-rain-delay"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("config_entry_unique_id", "entity_unique_id"),
|
||||||
|
[
|
||||||
|
(SERIAL_NUMBER, "1263613994342-rain-delay"),
|
||||||
|
# Some existing config entries may have a "0" serial number but preserve
|
||||||
|
# their unique id
|
||||||
|
(0, "0-rain-delay"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_unique_id(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
setup_integration: ComponentSetup,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
entity_unique_id: str,
|
||||||
|
) -> None:
|
||||||
|
"""Test number platform."""
|
||||||
|
|
||||||
|
assert await setup_integration()
|
||||||
|
|
||||||
|
raindelay = hass.states.get("number.rain_bird_controller_rain_delay")
|
||||||
|
assert raindelay is not None
|
||||||
|
assert (
|
||||||
|
raindelay.attributes.get("friendly_name") == "Rain Bird Controller Rain delay"
|
||||||
|
)
|
||||||
|
|
||||||
|
entity_entry = entity_registry.async_get("number.rain_bird_controller_rain_delay")
|
||||||
|
assert entity_entry
|
||||||
|
assert entity_entry.unique_id == entity_unique_id
|
||||||
|
|
||||||
|
|
||||||
async def test_set_value(
|
async def test_set_value(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
setup_integration: ComponentSetup,
|
setup_integration: ComponentSetup,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user