mirror of
https://github.com/esphome/esphome.git
synced 2026-09-30 00:10:22 +00:00
[pzem6l24] Add PZEM-6L24 three-phase energy monitor sensor (#17849)
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>
This commit is contained in:
co-authored by
Claude Sonnet 5
Copilot Autofix powered by AI
J. Nick Koston
parent
d5d0901e2c
commit
bfe1f7bd17
@@ -0,0 +1,28 @@
|
||||
"""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})
|
||||
Reference in New Issue
Block a user