"""Geraetename und Modellbeschreibung, auch wenn das Geraet wenig meldet.""" from __future__ import annotations from typing import Any from freezegun.api import FrozenDateTimeFactory from homeassistant.const import ATTR_ENTITY_ID, STATE_ON from homeassistant.core import HomeAssistant import pytest from pytest_homeassistant_custom_component.common import MockConfigEntry from custom_components.ninstrip.entity import device_name, strip_model from tests.helpers import abfragen, entity_id_for def test_eigener_name_hat_vorrang() -> None: assert device_name({"name": " Stehlampe ", "mac": "b0:81:84:49:ad:4c"}) == "Stehlampe" def test_ohne_namen_zaehlen_produkt_und_die_letzten_vier_mac_stellen() -> None: assert device_name({"name": "", "mac": "b0:81:84:49:ad:4c"}) == "ninstrip ad4c" assert device_name({"mac": "b0:81:84:49:ad:4c", "product": "ninstrip"}) == "ninstrip ad4c" @pytest.mark.parametrize( ("info", "erwartet"), [ ({"strip": {"chipset": "ws2805", "pixel_count": 40}}, "ws2805, 40 Pixel"), ({"strip": {"chipset": "ws2805"}}, "ws2805"), ({"strip": {}}, None), ({}, None), # Geraet im Onboarding: noch kein strip-Block ], ) def test_modellbeschreibung(info: dict[str, Any], erwartet: str | None) -> None: assert strip_model(info) == erwartet async def test_sacn_schalter_laesst_sich_auch_einschalten( hass: HomeAssistant, init_integration: MockConfigEntry, strip_settings: dict[str, Any], freezer: FrozenDateTimeFactory, ) -> None: strip_settings["sacn"]["enabled"] = False await abfragen(hass, freezer) entity_id = entity_id_for(hass, "switch", "sacn_enabled") await hass.services.async_call("switch", "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True) assert hass.states.get(entity_id).state == STATE_ON async def test_helligkeit_ohne_wert_bleibt_leer( hass: HomeAssistant, init_integration: MockConfigEntry, strip_state: dict[str, Any], freezer: FrozenDateTimeFactory, ) -> None: strip_state["brightness"] = None await abfragen(hass, freezer) assert hass.states.get(entity_id_for(hass, "light", "light")).attributes["brightness"] is None