init home-assistant

This commit is contained in:
2026-11-19 15:15:32 -05:00
parent 2e81d9d300
commit feec6ef9fb
19230 changed files with 3335526 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
"""Test binary sensors of APCUPSd integration."""
import pytest
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.util import slugify
from . import MOCK_STATUS, async_init_integration
async def test_binary_sensor(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test states of binary sensor."""
await async_init_integration(hass, status=MOCK_STATUS)
device_slug, serialno = slugify(MOCK_STATUS["UPSNAME"]), MOCK_STATUS["SERIALNO"]
state = hass.states.get(f"binary_sensor.{device_slug}_online_status")
assert state
assert state.state == "on"
entry = entity_registry.async_get(f"binary_sensor.{device_slug}_online_status")
assert entry
assert entry.unique_id == f"{serialno}_statflag"
async def test_no_binary_sensor(hass: HomeAssistant) -> None:
"""Test binary sensor when STATFLAG is not available."""
status = MOCK_STATUS.copy()
status.pop("STATFLAG")
await async_init_integration(hass, status=status)
device_slug = slugify(MOCK_STATUS["UPSNAME"])
state = hass.states.get(f"binary_sensor.{device_slug}_online_status")
assert state is None
@pytest.mark.parametrize(
("override", "expected"),
[
("0x008", "on"),
("0x02040010 Status Flag", "off"),
],
)
async def test_statflag(hass: HomeAssistant, override: str, expected: str) -> None:
"""Test binary sensor for different STATFLAG values."""
status = MOCK_STATUS.copy()
status["STATFLAG"] = override
await async_init_integration(hass, status=status)
device_slug = slugify(MOCK_STATUS["UPSNAME"])
assert (
hass.states.get(f"binary_sensor.{device_slug}_online_status").state == expected
)