mirror of
https://github.com/esphome/esphome.git
synced 2026-09-29 07:50:21 +00:00
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: J. Nick Koston <nick@home-assistant.io>
29 lines
873 B
Python
29 lines
873 B
Python
"""The PZEM-6L24 answers unit addresses 1 to 247 only."""
|
|
|
|
import pytest
|
|
|
|
from esphome import config_validation as cv
|
|
from esphome.components import modbus
|
|
from esphome.components.pzem6l24.sensor import CONFIG_SCHEMA
|
|
from esphome.const import CONF_ADDRESS
|
|
from esphome.types import ConfigType
|
|
|
|
|
|
def _sensor(**extra: object) -> ConfigType:
|
|
return CONFIG_SCHEMA({modbus.CONF_MODBUS_ID: "bus", **extra})
|
|
|
|
|
|
def test_address_defaults_to_one() -> None:
|
|
assert _sensor()[CONF_ADDRESS] == 1
|
|
|
|
|
|
@pytest.mark.parametrize("address", [1, 247])
|
|
def test_address_in_unit_range_accepted(address: int) -> None:
|
|
assert _sensor(**{CONF_ADDRESS: address})[CONF_ADDRESS] == address
|
|
|
|
|
|
@pytest.mark.parametrize("address", [0, 248, 255])
|
|
def test_address_outside_unit_range_rejected(address: int) -> None:
|
|
with pytest.raises(cv.Invalid):
|
|
_sensor(**{CONF_ADDRESS: address})
|