mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Switcher add current current temperature sensor (#130653)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
5b0d8eb75e
commit
6279979d50
@ -20,6 +20,9 @@
|
||||
},
|
||||
"auto_shutdown": {
|
||||
"default": "mdi:progress-clock"
|
||||
},
|
||||
"temperature": {
|
||||
"default": "mdi:thermometer"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -46,9 +46,16 @@ TIME_SENSORS: list[SensorEntityDescription] = [
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
]
|
||||
TEMPERATURE_SENSORS: list[SensorEntityDescription] = [
|
||||
SensorEntityDescription(
|
||||
key="temperature",
|
||||
translation_key="temperature",
|
||||
),
|
||||
]
|
||||
|
||||
POWER_PLUG_SENSORS = POWER_SENSORS
|
||||
WATER_HEATER_SENSORS = [*POWER_SENSORS, *TIME_SENSORS]
|
||||
THERMOSTAT_SENSORS = TEMPERATURE_SENSORS
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
@ -71,6 +78,11 @@ async def async_setup_entry(
|
||||
SwitcherSensorEntity(coordinator, description)
|
||||
for description in WATER_HEATER_SENSORS
|
||||
)
|
||||
elif coordinator.data.device_type.category == DeviceCategory.THERMOSTAT:
|
||||
async_add_entities(
|
||||
SwitcherSensorEntity(coordinator, description)
|
||||
for description in THERMOSTAT_SENSORS
|
||||
)
|
||||
|
||||
config_entry.async_on_unload(
|
||||
async_dispatcher_connect(hass, SIGNAL_DEVICE_ADD, async_add_sensors)
|
||||
|
@ -59,6 +59,9 @@
|
||||
},
|
||||
"auto_shutdown": {
|
||||
"name": "Auto shutdown"
|
||||
},
|
||||
"temperature": {
|
||||
"name": "Current temperature"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -219,3 +219,9 @@ DUMMY_TRIPLE_LIGHT_DEVICE = SwitcherLight(
|
||||
)
|
||||
|
||||
DUMMY_SWITCHER_DEVICES = [DUMMY_PLUG_DEVICE, DUMMY_WATER_HEATER_DEVICE]
|
||||
|
||||
DUMMY_SWITCHER_SENSORS_DEVICES = [
|
||||
DUMMY_PLUG_DEVICE,
|
||||
DUMMY_WATER_HEATER_DEVICE,
|
||||
DUMMY_THERMOSTAT_DEVICE,
|
||||
]
|
||||
|
@ -7,7 +7,12 @@ from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.util import slugify
|
||||
|
||||
from . import init_integration
|
||||
from .consts import DUMMY_PLUG_DEVICE, DUMMY_SWITCHER_DEVICES, DUMMY_WATER_HEATER_DEVICE
|
||||
from .consts import (
|
||||
DUMMY_PLUG_DEVICE,
|
||||
DUMMY_SWITCHER_SENSORS_DEVICES,
|
||||
DUMMY_THERMOSTAT_DEVICE,
|
||||
DUMMY_WATER_HEATER_DEVICE,
|
||||
)
|
||||
|
||||
DEVICE_SENSORS_TUPLE = (
|
||||
(
|
||||
@ -25,17 +30,23 @@ DEVICE_SENSORS_TUPLE = (
|
||||
("remaining_time", "remaining_time"),
|
||||
],
|
||||
),
|
||||
(
|
||||
DUMMY_THERMOSTAT_DEVICE,
|
||||
[
|
||||
("current_temperature", "temperature"),
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mock_bridge", [DUMMY_SWITCHER_DEVICES], indirect=True)
|
||||
@pytest.mark.parametrize("mock_bridge", [DUMMY_SWITCHER_SENSORS_DEVICES], indirect=True)
|
||||
async def test_sensor_platform(hass: HomeAssistant, mock_bridge) -> None:
|
||||
"""Test sensor platform."""
|
||||
entry = await init_integration(hass)
|
||||
assert mock_bridge
|
||||
|
||||
assert mock_bridge.is_running is True
|
||||
assert len(entry.runtime_data) == 2
|
||||
assert len(entry.runtime_data) == 3
|
||||
|
||||
for device, sensors in DEVICE_SENSORS_TUPLE:
|
||||
for sensor, field in sensors:
|
||||
|
Loading…
x
Reference in New Issue
Block a user