Add binary sensors to TechnoVE integration (#108938)

* Add binary sensors to TechnoVE integration

* Add unit tests for TechnoVE binary sensors

* Implement PR feedback for TechnoVE

* Limit to appropriate sensors in TechnoVE tests

* Removed leftover code

* Implement feedback in TechnoVE PR #108938
This commit is contained in:
Christophe Gagnier 2024-01-29 05:56:57 -05:00 committed by GitHub
parent d45227adbb
commit 91e7e5e01a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 478 additions and 207 deletions

View file

@ -8,7 +8,10 @@ from homeassistant.core import HomeAssistant
from .const import DOMAIN
from .coordinator import TechnoVEDataUpdateCoordinator
PLATFORMS = [Platform.SENSOR]
PLATFORMS = [
Platform.BINARY_SENSOR,
Platform.SENSOR,
]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

View file

@ -0,0 +1,103 @@
"""Support for TechnoVE binary sensor."""
from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass
from technove import Station as TechnoVEStation
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN
from .coordinator import TechnoVEDataUpdateCoordinator
from .entity import TechnoVEEntity
@dataclass(frozen=True, kw_only=True)
class TechnoVEBinarySensorDescription(BinarySensorEntityDescription):
"""Describes TechnoVE binary sensor entity."""
value_fn: Callable[[TechnoVEStation], bool | None]
BINARY_SENSORS = [
TechnoVEBinarySensorDescription(
key="conflict_in_sharing_config",
translation_key="conflict_in_sharing_config",
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda station: station.info.conflict_in_sharing_config,
),
TechnoVEBinarySensorDescription(
key="in_sharing_mode",
translation_key="in_sharing_mode",
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda station: station.info.in_sharing_mode,
),
TechnoVEBinarySensorDescription(
key="is_battery_protected",
translation_key="is_battery_protected",
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda station: station.info.is_battery_protected,
),
TechnoVEBinarySensorDescription(
key="is_session_active",
entity_category=EntityCategory.DIAGNOSTIC,
device_class=BinarySensorDeviceClass.BATTERY_CHARGING,
value_fn=lambda station: station.info.is_session_active,
),
TechnoVEBinarySensorDescription(
key="is_static_ip",
translation_key="is_static_ip",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
value_fn=lambda station: station.info.is_static_ip,
),
TechnoVEBinarySensorDescription(
key="update_available",
entity_category=EntityCategory.DIAGNOSTIC,
device_class=BinarySensorDeviceClass.UPDATE,
value_fn=lambda station: not station.info.is_up_to_date,
),
]
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the binary sensor platform."""
coordinator: TechnoVEDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
async_add_entities(
TechnoVEBinarySensorEntity(coordinator, description)
for description in BINARY_SENSORS
)
class TechnoVEBinarySensorEntity(TechnoVEEntity, BinarySensorEntity):
"""Defines a TechnoVE binary sensor entity."""
entity_description: TechnoVEBinarySensorDescription
def __init__(
self,
coordinator: TechnoVEDataUpdateCoordinator,
description: TechnoVEBinarySensorDescription,
) -> None:
"""Initialize a TechnoVE binary sensor entity."""
self.entity_description = description
super().__init__(coordinator, description.key)
@property
def is_on(self) -> bool | None:
"""Return the state of the sensor."""
return self.entity_description.value_fn(self.coordinator.data)

View file

@ -25,6 +25,20 @@
}
},
"entity": {
"binary_sensor": {
"conflict_in_sharing_config": {
"name": "Conflict with power sharing mode"
},
"in_sharing_mode": {
"name": "Power sharing mode"
},
"is_battery_protected": {
"name": "Battery protected"
},
"is_static_ip": {
"name": "Static IP"
}
},
"sensor": {
"voltage_in": {
"name": "Input voltage"

View file

@ -1 +1,17 @@
"""Tests for the TechnoVE integration."""
from unittest.mock import patch
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
async def setup_with_selected_platforms(
hass: HomeAssistant, entry: MockConfigEntry, platforms: list[Platform]
) -> None:
"""Set up the TechnoVE integration with the selected platforms."""
entry.add_to_hass(hass)
with patch("homeassistant.components.technove.PLATFORMS", platforms):
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()

View file

@ -0,0 +1,261 @@
# serializer version: 1
# name: test_sensors[binary_sensor.technove_station_battery_protected-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'binary_sensor.technove_station_battery_protected',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Battery protected',
'platform': 'technove',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'is_battery_protected',
'unique_id': 'AA:AA:AA:AA:AA:BB_is_battery_protected',
'unit_of_measurement': None,
})
# ---
# name: test_sensors[binary_sensor.technove_station_battery_protected-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'TechnoVE Station Battery protected',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.technove_station_battery_protected',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_sensors[binary_sensor.technove_station_charging-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'binary_sensor.technove_station_charging',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': <BinarySensorDeviceClass.BATTERY_CHARGING: 'battery_charging'>,
'original_icon': None,
'original_name': 'Charging',
'platform': 'technove',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': 'AA:AA:AA:AA:AA:BB_is_session_active',
'unit_of_measurement': None,
})
# ---
# name: test_sensors[binary_sensor.technove_station_charging-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'battery_charging',
'friendly_name': 'TechnoVE Station Charging',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.technove_station_charging',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_sensors[binary_sensor.technove_station_conflict_with_power_sharing_mode-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'binary_sensor.technove_station_conflict_with_power_sharing_mode',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Conflict with power sharing mode',
'platform': 'technove',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'conflict_in_sharing_config',
'unique_id': 'AA:AA:AA:AA:AA:BB_conflict_in_sharing_config',
'unit_of_measurement': None,
})
# ---
# name: test_sensors[binary_sensor.technove_station_conflict_with_power_sharing_mode-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'TechnoVE Station Conflict with power sharing mode',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.technove_station_conflict_with_power_sharing_mode',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_sensors[binary_sensor.technove_station_power_sharing_mode-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'binary_sensor.technove_station_power_sharing_mode',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Power sharing mode',
'platform': 'technove',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'in_sharing_mode',
'unique_id': 'AA:AA:AA:AA:AA:BB_in_sharing_mode',
'unit_of_measurement': None,
})
# ---
# name: test_sensors[binary_sensor.technove_station_power_sharing_mode-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'TechnoVE Station Power sharing mode',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.technove_station_power_sharing_mode',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_sensors[binary_sensor.technove_station_static_ip-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'binary_sensor.technove_station_static_ip',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Static IP',
'platform': 'technove',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'is_static_ip',
'unique_id': 'AA:AA:AA:AA:AA:BB_is_static_ip',
'unit_of_measurement': None,
})
# ---
# name: test_sensors[binary_sensor.technove_station_static_ip-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'TechnoVE Station Static IP',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.technove_station_static_ip',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_sensors[binary_sensor.technove_station_update-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'binary_sensor.technove_station_update',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': <BinarySensorDeviceClass.UPDATE: 'update'>,
'original_icon': None,
'original_name': 'Update',
'platform': 'technove',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': 'AA:AA:AA:AA:AA:BB_update_available',
'unit_of_measurement': None,
})
# ---
# name: test_sensors[binary_sensor.technove_station_update-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'update',
'friendly_name': 'TechnoVE Station Update',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.technove_station_update',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---

View file

@ -47,21 +47,6 @@
'state': '23.75',
})
# ---
# name: test_sensors[sensor.technove_station_current]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'current',
'friendly_name': 'TechnoVE Station Current',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfElectricCurrent.AMPERE: 'A'>,
}),
'context': <ANY>,
'entity_id': 'sensor.technove_station_current',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '23.75',
})
# ---
# name: test_sensors[sensor.technove_station_input_voltage-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
@ -110,21 +95,6 @@
'state': '238',
})
# ---
# name: test_sensors[sensor.technove_station_input_voltage]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'voltage',
'friendly_name': 'TechnoVE Station Input voltage',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfElectricPotential.VOLT: 'V'>,
}),
'context': <ANY>,
'entity_id': 'sensor.technove_station_input_voltage',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '238',
})
# ---
# name: test_sensors[sensor.technove_station_last_session_energy_usage-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
@ -173,84 +143,6 @@
'state': '12.34',
})
# ---
# name: test_sensors[sensor.technove_station_last_session_energy_usage]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'energy',
'friendly_name': 'TechnoVE Station Last session energy usage',
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
}),
'context': <ANY>,
'entity_id': 'sensor.technove_station_last_session_energy_usage',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '12.34',
})
# ---
# name: test_sensors[sensor.technove_station_max_current-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.technove_station_max_current',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.CURRENT: 'current'>,
'original_icon': None,
'original_name': 'Max current',
'platform': 'technove',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'max_current',
'unique_id': 'AA:AA:AA:AA:AA:BB_max_current',
'unit_of_measurement': <UnitOfElectricCurrent.AMPERE: 'A'>,
})
# ---
# name: test_sensors[sensor.technove_station_max_current-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'current',
'friendly_name': 'TechnoVE Station Max current',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfElectricCurrent.AMPERE: 'A'>,
}),
'context': <ANY>,
'entity_id': 'sensor.technove_station_max_current',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '24',
})
# ---
# name: test_sensors[sensor.technove_station_max_current]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'current',
'friendly_name': 'TechnoVE Station Max current',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfElectricCurrent.AMPERE: 'A'>,
}),
'context': <ANY>,
'entity_id': 'sensor.technove_station_max_current',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '24',
})
# ---
# name: test_sensors[sensor.technove_station_max_station_current-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
@ -299,21 +191,6 @@
'state': '32',
})
# ---
# name: test_sensors[sensor.technove_station_max_station_current]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'current',
'friendly_name': 'TechnoVE Station Max station current',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfElectricCurrent.AMPERE: 'A'>,
}),
'context': <ANY>,
'entity_id': 'sensor.technove_station_max_station_current',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '32',
})
# ---
# name: test_sensors[sensor.technove_station_output_voltage-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
@ -362,21 +239,6 @@
'state': '238',
})
# ---
# name: test_sensors[sensor.technove_station_output_voltage]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'voltage',
'friendly_name': 'TechnoVE Station Output voltage',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfElectricPotential.VOLT: 'V'>,
}),
'context': <ANY>,
'entity_id': 'sensor.technove_station_output_voltage',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '238',
})
# ---
# name: test_sensors[sensor.technove_station_signal_strength-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
@ -425,21 +287,6 @@
'state': '-82',
})
# ---
# name: test_sensors[sensor.technove_station_signal_strength]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'signal_strength',
'friendly_name': 'TechnoVE Station Signal strength',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': 'dBm',
}),
'context': <ANY>,
'entity_id': 'sensor.technove_station_signal_strength',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '-82',
})
# ---
# name: test_sensors[sensor.technove_station_status-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
@ -495,24 +342,6 @@
'state': 'plugged_charging',
})
# ---
# name: test_sensors[sensor.technove_station_status]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'enum',
'friendly_name': 'TechnoVE Station Status',
'options': list([
'unplugged',
'plugged_waiting',
'plugged_charging',
]),
}),
'context': <ANY>,
'entity_id': 'sensor.technove_station_status',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'plugged_charging',
})
# ---
# name: test_sensors[sensor.technove_station_total_energy_usage-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
@ -561,21 +390,6 @@
'state': '1234',
})
# ---
# name: test_sensors[sensor.technove_station_total_energy_usage]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'energy',
'friendly_name': 'TechnoVE Station Total energy usage',
'state_class': <SensorStateClass.TOTAL: 'total'>,
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
}),
'context': <ANY>,
'entity_id': 'sensor.technove_station_total_energy_usage',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '1234',
})
# ---
# name: test_sensors[sensor.technove_station_wi_fi_network_name-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
@ -620,16 +434,3 @@
'state': 'Connecting...',
})
# ---
# name: test_sensors[sensor.technove_station_wi_fi_network_name]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'TechnoVE Station Wi-Fi network name',
'icon': 'mdi:wifi',
}),
'context': <ANY>,
'entity_id': 'sensor.technove_station_wi_fi_network_name',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'Connecting...',
})
# ---

View file

@ -0,0 +1,75 @@
"""Tests for the TechnoVE binary sensor platform."""
from datetime import timedelta
from unittest.mock import MagicMock
from freezegun.api import FrozenDateTimeFactory
import pytest
from syrupy import SnapshotAssertion
from technove import TechnoVEError
from homeassistant.const import STATE_ON, STATE_UNAVAILABLE, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from . import setup_with_selected_platforms
from tests.common import MockConfigEntry, async_fire_time_changed
@pytest.mark.usefixtures("entity_registry_enabled_by_default", "mock_technove")
async def test_sensors(
hass: HomeAssistant,
snapshot: SnapshotAssertion,
mock_config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test the creation and values of the TechnoVE binary sensors."""
await setup_with_selected_platforms(
hass, mock_config_entry, [Platform.BINARY_SENSOR]
)
entity_entries = er.async_entries_for_config_entry(
entity_registry, mock_config_entry.entry_id
)
assert entity_entries
for entity_entry in entity_entries:
assert entity_entry == snapshot(name=f"{entity_entry.entity_id}-entry")
assert hass.states.get(entity_entry.entity_id) == snapshot(
name=f"{entity_entry.entity_id}-state"
)
@pytest.mark.parametrize(
"entity_id",
("binary_sensor.technove_station_static_ip",),
)
@pytest.mark.usefixtures("init_integration")
async def test_disabled_by_default_binary_sensors(
hass: HomeAssistant, entity_registry: er.EntityRegistry, entity_id: str
) -> None:
"""Test the disabled by default TechnoVE binary sensors."""
assert hass.states.get(entity_id) is None
assert (entry := entity_registry.async_get(entity_id))
assert entry.disabled
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
@pytest.mark.usefixtures("init_integration")
async def test_binary_sensor_update_failure(
hass: HomeAssistant,
mock_technove: MagicMock,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test coordinator update failure."""
entity_id = "binary_sensor.technove_station_charging"
assert hass.states.get(entity_id).state == STATE_ON
mock_technove.update.side_effect = TechnoVEError("Test error")
freezer.tick(timedelta(minutes=5, seconds=1))
async_fire_time_changed(hass)
await hass.async_block_till_done()
assert hass.states.get(entity_id).state == STATE_UNAVAILABLE

View file

@ -7,10 +7,12 @@ import pytest
from syrupy import SnapshotAssertion
from technove import Status, TechnoVEError
from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN
from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from . import setup_with_selected_platforms
from tests.common import MockConfigEntry, async_fire_time_changed
@ -22,11 +24,7 @@ async def test_sensors(
entity_registry: er.EntityRegistry,
) -> None:
"""Test the creation and values of the TechnoVE sensors."""
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
entity_registry = er.async_get(hass)
await setup_with_selected_platforms(hass, mock_config_entry, [Platform.SENSOR])
entity_entries = er.async_entries_for_config_entry(
entity_registry, mock_config_entry.entry_id
)
@ -89,9 +87,9 @@ async def test_sensor_update_failure(
assert hass.states.get(entity_id).state == Status.PLUGGED_CHARGING.value
mock_technove.update.side_effect = TechnoVEError("Test error")
freezer.tick(timedelta(minutes=5, seconds=1))
async_fire_time_changed(hass)
mock_technove.update.side_effect = TechnoVEError("Test error")
await hass.async_block_till_done()
assert hass.states.get(entity_id).state == STATE_UNAVAILABLE