hass-core/tests/components/v2c/test_sensor.py
Diogo Gomes 822273a6a3
Add support for V2C Trydan 2.1.7 (#117147)
* Support for firmware 2.1.7

* add device ID as unique_id

* add device ID as unique_id

* add test device id as unique_id

* backward compatibility

* move outside try

* Sensor return type

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* not needed

* make slave error enum state

* fix enum

* Update homeassistant/components/v2c/sensor.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update homeassistant/components/v2c/strings.json

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update homeassistant/components/v2c/strings.json

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* simplify tests

* fix misspellings from upstream library

* add sensor tests

* just enough coverage for enum sensor

* Refactor V2C tests (#117264)

* Refactor V2C tests

* fix rebase issues

* ruff

* review

* fix https://github.com/home-assistant/core/issues/117296

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-05-30 20:42:48 +02:00

67 lines
1.9 KiB
Python

"""Test the V2C sensor platform."""
from unittest.mock import AsyncMock, patch
from syrupy import SnapshotAssertion
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from . import init_integration
from tests.common import MockConfigEntry, snapshot_platform
async def test_sensor(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
mock_v2c_client: AsyncMock,
mock_config_entry: MockConfigEntry,
entity_registry_enabled_by_default: None,
) -> None:
"""Test states of the sensor."""
with patch("homeassistant.components.v2c.PLATFORMS", [Platform.SENSOR]):
await init_integration(hass, mock_config_entry)
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
from homeassistant.components.v2c.sensor import _SLAVE_ERROR_OPTIONS
assert [
"no_error",
"communication",
"reading",
"slave",
"waiting_wifi",
"waiting_communication",
"wrong_ip",
"slave_not_found",
"wrong_slave",
"no_response",
"clamp_not_connected",
"illegal_function",
"illegal_data_address",
"illegal_data_value",
"server_device_failure",
"acknowledge",
"server_device_busy",
"negative_acknowledge",
"memory_parity_error",
"gateway_path_unavailable",
"gateway_target_no_resp",
"server_rtu_inactive244_timeout",
"invalid_server",
"crc_error",
"fc_mismatch",
"server_id_mismatch",
"packet_length_error",
"parameter_count_error",
"parameter_limit_error",
"request_queue_full",
"illegal_ip_or_port",
"ip_connection_failed",
"tcp_head_mismatch",
"empty_message",
"undefined_error",
] == _SLAVE_ERROR_OPTIONS