Always setup demo platforms with device support from config entry (#94586)
* Always setup demo platforms with device support from config entry * Adjust test fixutres * Update tests depending on the demo integration
This commit is contained in:
parent
1b8c72e644
commit
9a3077d64a
54 changed files with 491 additions and 351 deletions
|
@ -14,27 +14,24 @@ from homeassistant.components.climate import (
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import DOMAIN
|
||||
|
||||
SUPPORT_FLAGS = ClimateEntityFeature(0)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Demo climate devices."""
|
||||
"""Set up the demo climate platform."""
|
||||
async_add_entities(
|
||||
[
|
||||
DemoClimate(
|
||||
unique_id="climate_1",
|
||||
name="HeatPump",
|
||||
device_name="HeatPump",
|
||||
target_temperature=68,
|
||||
unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
|
||||
preset=None,
|
||||
|
@ -52,7 +49,7 @@ async def async_setup_platform(
|
|||
),
|
||||
DemoClimate(
|
||||
unique_id="climate_2",
|
||||
name="Hvac",
|
||||
device_name="Hvac",
|
||||
target_temperature=21,
|
||||
unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
preset=None,
|
||||
|
@ -70,7 +67,7 @@ async def async_setup_platform(
|
|||
),
|
||||
DemoClimate(
|
||||
unique_id="climate_3",
|
||||
name="Ecobee",
|
||||
device_name="Ecobee",
|
||||
target_temperature=None,
|
||||
unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
preset="home",
|
||||
|
@ -91,25 +88,17 @@ async def async_setup_platform(
|
|||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Demo climate devices config entry."""
|
||||
await async_setup_platform(hass, {}, async_add_entities)
|
||||
|
||||
|
||||
class DemoClimate(ClimateEntity):
|
||||
"""Representation of a demo climate device."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
_attr_should_poll = False
|
||||
_attr_translation_key = "ubercool"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
unique_id: str,
|
||||
name: str,
|
||||
device_name: str,
|
||||
target_temperature: float | None,
|
||||
unit_of_measurement: str,
|
||||
preset: str | None,
|
||||
|
@ -128,7 +117,6 @@ class DemoClimate(ClimateEntity):
|
|||
) -> None:
|
||||
"""Initialize the climate device."""
|
||||
self._unique_id = unique_id
|
||||
self._attr_name = name
|
||||
self._attr_supported_features = SUPPORT_FLAGS
|
||||
if target_temperature is not None:
|
||||
self._attr_supported_features |= ClimateEntityFeature.TARGET_TEMPERATURE
|
||||
|
@ -163,17 +151,10 @@ class DemoClimate(ClimateEntity):
|
|||
self._swing_modes = ["auto", "1", "2", "3", "off"]
|
||||
self._target_temperature_high = target_temp_high
|
||||
self._target_temperature_low = target_temp_low
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device info."""
|
||||
return DeviceInfo(
|
||||
identifiers={
|
||||
# Serial numbers are unique identifiers within a specific domain
|
||||
(DOMAIN, self.unique_id)
|
||||
},
|
||||
name=self.name,
|
||||
)
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, unique_id)},
|
||||
"name": device_name,
|
||||
}
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue