Improve vallox tests and code quality (#75787)

code quality improvements
This commit is contained in:
Jevgeni Kiski 2022-10-02 07:13:15 +03:00 committed by GitHub
parent 38a680c3eb
commit f95b8ccc20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 6 deletions

View file

@ -16,7 +16,7 @@ from . import ValloxDataUpdateCoordinator, ValloxEntity
from .const import DOMAIN from .const import DOMAIN
class ValloxBinarySensor(ValloxEntity, BinarySensorEntity): class ValloxBinarySensorEntity(ValloxEntity, BinarySensorEntity):
"""Representation of a Vallox binary sensor.""" """Representation of a Vallox binary sensor."""
entity_description: ValloxBinarySensorEntityDescription entity_description: ValloxBinarySensorEntityDescription
@ -56,7 +56,7 @@ class ValloxBinarySensorEntityDescription(
"""Describes Vallox binary sensor entity.""" """Describes Vallox binary sensor entity."""
SENSORS: tuple[ValloxBinarySensorEntityDescription, ...] = ( BINARY_SENSOR_ENTITIES: tuple[ValloxBinarySensorEntityDescription, ...] = (
ValloxBinarySensorEntityDescription( ValloxBinarySensorEntityDescription(
key="post_heater", key="post_heater",
name="Post heater", name="Post heater",
@ -77,7 +77,7 @@ async def async_setup_entry(
async_add_entities( async_add_entities(
[ [
ValloxBinarySensor(data["name"], data["coordinator"], description) ValloxBinarySensorEntity(data["name"], data["coordinator"], description)
for description in SENSORS for description in BINARY_SENSOR_ENTITIES
] ]
) )

View file

@ -70,7 +70,7 @@ async def async_setup_entry(
client = data["client"] client = data["client"]
client.set_settable_address(METRIC_KEY_MODE, int) client.set_settable_address(METRIC_KEY_MODE, int)
device = ValloxFan( device = ValloxFanEntity(
data["name"], data["name"],
client, client,
data["coordinator"], data["coordinator"],
@ -79,7 +79,7 @@ async def async_setup_entry(
async_add_entities([device]) async_add_entities([device])
class ValloxFan(ValloxEntity, FanEntity): class ValloxFanEntity(ValloxEntity, FanEntity):
"""Representation of the fan.""" """Representation of the fan."""
_attr_supported_features = FanEntityFeature.PRESET_MODE _attr_supported_features = FanEntityFeature.PRESET_MODE

View 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