mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Add Enum device class for HomeWizard active tariff (#86078)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
8485588aca
commit
0f3221eac7
@ -74,7 +74,11 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
|
|||||||
key="active_tariff",
|
key="active_tariff",
|
||||||
name="Active tariff",
|
name="Active tariff",
|
||||||
icon="mdi:calendar-clock",
|
icon="mdi:calendar-clock",
|
||||||
value_fn=lambda data: data.active_tariff,
|
value_fn=lambda data: (
|
||||||
|
None if data.active_tariff is None else str(data.active_tariff)
|
||||||
|
),
|
||||||
|
device_class=SensorDeviceClass.ENUM,
|
||||||
|
options=["1", "2", "3", "4"],
|
||||||
),
|
),
|
||||||
HomeWizardSensorEntityDescription(
|
HomeWizardSensorEntityDescription(
|
||||||
key="wifi_strength",
|
key="wifi_strength",
|
||||||
|
@ -7,6 +7,7 @@ from homewizard_energy.errors import DisabledError, RequestError
|
|||||||
from homewizard_energy.models import Data
|
from homewizard_energy.models import Data
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
|
ATTR_OPTIONS,
|
||||||
ATTR_STATE_CLASS,
|
ATTR_STATE_CLASS,
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
@ -145,6 +146,45 @@ async def test_sensor_entity_wifi_ssid(hass, mock_config_entry_data, mock_config
|
|||||||
assert state.attributes.get(ATTR_ICON) == "mdi:wifi"
|
assert state.attributes.get(ATTR_ICON) == "mdi:wifi"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_sensor_entity_active_tariff(
|
||||||
|
hass, mock_config_entry_data, mock_config_entry
|
||||||
|
):
|
||||||
|
"""Test entity loads active_tariff."""
|
||||||
|
|
||||||
|
api = get_mock_device()
|
||||||
|
api.data = AsyncMock(return_value=Data.from_dict({"active_tariff": 2}))
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.homewizard.coordinator.HomeWizardEnergy",
|
||||||
|
return_value=api,
|
||||||
|
):
|
||||||
|
entry = mock_config_entry
|
||||||
|
entry.data = mock_config_entry_data
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
entity_registry = er.async_get(hass)
|
||||||
|
|
||||||
|
state = hass.states.get("sensor.product_name_aabbccddeeff_active_tariff")
|
||||||
|
entry = entity_registry.async_get("sensor.product_name_aabbccddeeff_active_tariff")
|
||||||
|
assert entry
|
||||||
|
assert state
|
||||||
|
assert entry.unique_id == "aabbccddeeff_active_tariff"
|
||||||
|
assert not entry.disabled
|
||||||
|
assert state.state == "2"
|
||||||
|
assert (
|
||||||
|
state.attributes.get(ATTR_FRIENDLY_NAME)
|
||||||
|
== "Product Name (aabbccddeeff) Active tariff"
|
||||||
|
)
|
||||||
|
assert ATTR_STATE_CLASS not in state.attributes
|
||||||
|
assert ATTR_UNIT_OF_MEASUREMENT not in state.attributes
|
||||||
|
assert state.attributes.get(ATTR_ICON) == "mdi:calendar-clock"
|
||||||
|
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENUM
|
||||||
|
assert state.attributes.get(ATTR_OPTIONS) == ["1", "2", "3", "4"]
|
||||||
|
|
||||||
|
|
||||||
async def test_sensor_entity_wifi_strength(
|
async def test_sensor_entity_wifi_strength(
|
||||||
hass, mock_config_entry_data, mock_config_entry
|
hass, mock_config_entry_data, mock_config_entry
|
||||||
):
|
):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user