mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
Do not set a device on YAML mold_indicator entities (#177600)
This commit is contained in:
committed by
Bram Kragten
parent
c4ac8e9517
commit
b7882ed7d5
@@ -162,7 +162,6 @@ def ws_start_preview(
|
||||
)
|
||||
|
||||
preview_entity = MoldIndicator(
|
||||
hass,
|
||||
name,
|
||||
hass.config.units is METRIC_SYSTEM,
|
||||
indoor_temp,
|
||||
|
||||
@@ -34,6 +34,7 @@ from homeassistant.core import (
|
||||
)
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.device import async_entity_id_to_device
|
||||
from homeassistant.helpers.device_registry import DeviceEntry
|
||||
from homeassistant.helpers.entity_platform import (
|
||||
AddConfigEntryEntitiesCallback,
|
||||
AddEntitiesCallback,
|
||||
@@ -89,7 +90,6 @@ async def async_setup_platform(
|
||||
async_add_entities(
|
||||
[
|
||||
MoldIndicator(
|
||||
hass,
|
||||
name,
|
||||
hass.config.units is METRIC_SYSTEM,
|
||||
indoor_temp_sensor,
|
||||
@@ -118,7 +118,6 @@ async def async_setup_entry(
|
||||
async_add_entities(
|
||||
[
|
||||
MoldIndicator(
|
||||
hass,
|
||||
name,
|
||||
hass.config.units is METRIC_SYSTEM,
|
||||
indoor_temp_sensor,
|
||||
@@ -126,6 +125,7 @@ async def async_setup_entry(
|
||||
indoor_humidity_sensor,
|
||||
calib_factor,
|
||||
entry.entry_id,
|
||||
device=async_entity_id_to_device(hass, indoor_humidity_sensor),
|
||||
)
|
||||
],
|
||||
False,
|
||||
@@ -142,7 +142,6 @@ class MoldIndicator(SensorEntity):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
name: str,
|
||||
is_metric: bool,
|
||||
indoor_temp_sensor: str,
|
||||
@@ -150,6 +149,7 @@ class MoldIndicator(SensorEntity):
|
||||
indoor_humidity_sensor: str,
|
||||
calib_factor: float,
|
||||
unique_id: str | None,
|
||||
device: DeviceEntry | None = None,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
self._attr_name = name
|
||||
@@ -168,11 +168,7 @@ class MoldIndicator(SensorEntity):
|
||||
self._outdoor_temp: float | None = None
|
||||
self._indoor_hum: float | None = None
|
||||
self._crit_temp: float | None = None
|
||||
if indoor_humidity_sensor:
|
||||
self.device_entry = async_entity_id_to_device(
|
||||
hass,
|
||||
indoor_humidity_sensor,
|
||||
)
|
||||
self.device_entry = device
|
||||
self._preview_callback: Callable[[str, Mapping[str, Any]], None] | None = None
|
||||
|
||||
@callback
|
||||
|
||||
@@ -15,6 +15,7 @@ from homeassistant.const import (
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
@@ -55,6 +56,51 @@ async def test_setup(hass: HomeAssistant) -> None:
|
||||
assert moldind.attributes.get("unit_of_measurement") == PERCENTAGE
|
||||
|
||||
|
||||
async def test_device_id_yaml(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test no device is set for a YAML-configured MoldIndicator."""
|
||||
source_config_entry = MockConfigEntry()
|
||||
source_config_entry.add_to_hass(hass)
|
||||
source_device_entry = device_registry.async_get_or_create(
|
||||
config_entry_id=source_config_entry.entry_id,
|
||||
identifiers={("sensor", "identifier_test")},
|
||||
connections={("mac", "30:31:32:33:34:35")},
|
||||
)
|
||||
entity_registry.async_get_or_create(
|
||||
"sensor",
|
||||
"test",
|
||||
"source",
|
||||
config_entry=source_config_entry,
|
||||
device_id=source_device_entry.id,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
sensor.DOMAIN,
|
||||
{
|
||||
"sensor": {
|
||||
"platform": "mold_indicator",
|
||||
"indoor_temp_sensor": "test.indoortemp",
|
||||
"outdoor_temp_sensor": "test.outdoortemp",
|
||||
"indoor_humidity_sensor": "sensor.test_source",
|
||||
"calibration_factor": 2.0,
|
||||
"unique_id": "mold_indicator_yaml",
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
mold_indicator_entity = entity_registry.async_get("sensor.mold_indicator")
|
||||
assert mold_indicator_entity is not None
|
||||
assert mold_indicator_entity.device_id is None
|
||||
assert "attempts to attach a device to an entity" not in caplog.text
|
||||
|
||||
|
||||
async def test_setup_from_config_entry(
|
||||
hass: HomeAssistant, loaded_entry: MockConfigEntry
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user