Improve vallox tests and code quality (#75787)
code quality improvements
This commit is contained in:
parent
38a680c3eb
commit
f95b8ccc20
3 changed files with 40 additions and 6 deletions
|
@ -16,7 +16,7 @@ from . import ValloxDataUpdateCoordinator, ValloxEntity
|
|||
from .const import DOMAIN
|
||||
|
||||
|
||||
class ValloxBinarySensor(ValloxEntity, BinarySensorEntity):
|
||||
class ValloxBinarySensorEntity(ValloxEntity, BinarySensorEntity):
|
||||
"""Representation of a Vallox binary sensor."""
|
||||
|
||||
entity_description: ValloxBinarySensorEntityDescription
|
||||
|
@ -56,7 +56,7 @@ class ValloxBinarySensorEntityDescription(
|
|||
"""Describes Vallox binary sensor entity."""
|
||||
|
||||
|
||||
SENSORS: tuple[ValloxBinarySensorEntityDescription, ...] = (
|
||||
BINARY_SENSOR_ENTITIES: tuple[ValloxBinarySensorEntityDescription, ...] = (
|
||||
ValloxBinarySensorEntityDescription(
|
||||
key="post_heater",
|
||||
name="Post heater",
|
||||
|
@ -77,7 +77,7 @@ async def async_setup_entry(
|
|||
|
||||
async_add_entities(
|
||||
[
|
||||
ValloxBinarySensor(data["name"], data["coordinator"], description)
|
||||
for description in SENSORS
|
||||
ValloxBinarySensorEntity(data["name"], data["coordinator"], description)
|
||||
for description in BINARY_SENSOR_ENTITIES
|
||||
]
|
||||
)
|
||||
|
|
|
@ -70,7 +70,7 @@ async def async_setup_entry(
|
|||
client = data["client"]
|
||||
client.set_settable_address(METRIC_KEY_MODE, int)
|
||||
|
||||
device = ValloxFan(
|
||||
device = ValloxFanEntity(
|
||||
data["name"],
|
||||
client,
|
||||
data["coordinator"],
|
||||
|
@ -79,7 +79,7 @@ async def async_setup_entry(
|
|||
async_add_entities([device])
|
||||
|
||||
|
||||
class ValloxFan(ValloxEntity, FanEntity):
|
||||
class ValloxFanEntity(ValloxEntity, FanEntity):
|
||||
"""Representation of the fan."""
|
||||
|
||||
_attr_supported_features = FanEntityFeature.PRESET_MODE
|
||||
|
|
34
tests/components/vallox/test_binary_sensor.py
Normal file
34
tests/components/vallox/test_binary_sensor.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
"""Tests for Vallox binary sensor platform."""
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .conftest import patch_metrics
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"metrics,expected_state",
|
||||
[
|
||||
({"A_CYC_IO_HEATER": 1}, "on"),
|
||||
({"A_CYC_IO_HEATER": 0}, "off"),
|
||||
],
|
||||
)
|
||||
async def test_binary_sensor_entitity(
|
||||
metrics: dict[str, Any],
|
||||
expected_state: str,
|
||||
mock_entry: MockConfigEntry,
|
||||
hass: HomeAssistant,
|
||||
):
|
||||
"""Test binary sensor with metrics."""
|
||||
# Act
|
||||
with patch_metrics(metrics=metrics):
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Assert
|
||||
sensor = hass.states.get("binary_sensor.vallox_post_heater")
|
||||
assert sensor.state == expected_state
|
Loading…
Add table
Reference in a new issue