mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Add brightness controls to LaMetric (#79804)
This commit is contained in:
parent
75886d7213
commit
d03e0380bb
@ -34,6 +34,18 @@ class LaMetricNumberEntityDescription(
|
||||
|
||||
|
||||
NUMBERS = [
|
||||
LaMetricNumberEntityDescription(
|
||||
key="brightness",
|
||||
name="Brightness",
|
||||
icon="mdi:brightness-6",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
native_step=1,
|
||||
native_min_value=0,
|
||||
native_max_value=100,
|
||||
native_unit_of_measurement="%",
|
||||
value_fn=lambda device: device.display.brightness,
|
||||
set_value_fn=lambda device, bri: device.display(brightness=int(bri)),
|
||||
),
|
||||
LaMetricNumberEntityDescription(
|
||||
key="volume",
|
||||
name="Volume",
|
||||
|
@ -2,18 +2,20 @@
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from homeassistant.components.lametric.const import DOMAIN
|
||||
from homeassistant.components.number import DOMAIN as NUMBER_DOMAIN, SERVICE_SET_VALUE
|
||||
from homeassistant.components.number.const import (
|
||||
from homeassistant.components.number import (
|
||||
ATTR_MAX,
|
||||
ATTR_MIN,
|
||||
ATTR_STEP,
|
||||
ATTR_VALUE,
|
||||
DOMAIN as NUMBER_DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_DEVICE_CLASS,
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_FRIENDLY_NAME,
|
||||
ATTR_ICON,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
@ -22,6 +24,58 @@ from homeassistant.helpers.entity import EntityCategory
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_brightness(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_lametric: MagicMock,
|
||||
) -> None:
|
||||
"""Test the LaMetric display brightness controls."""
|
||||
device_registry = dr.async_get(hass)
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
state = hass.states.get("number.frenck_s_lametric_brightness")
|
||||
assert state
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Frenck's LaMetric Brightness"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:brightness-6"
|
||||
assert state.attributes.get(ATTR_MAX) == 100
|
||||
assert state.attributes.get(ATTR_MIN) == 0
|
||||
assert state.attributes.get(ATTR_STEP) == 1
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "%"
|
||||
assert state.state == "100"
|
||||
|
||||
entry = entity_registry.async_get(state.entity_id)
|
||||
assert entry
|
||||
assert entry.device_id
|
||||
assert entry.entity_category is EntityCategory.CONFIG
|
||||
assert entry.unique_id == "SA110405124500W00BS9-brightness"
|
||||
|
||||
device = device_registry.async_get(entry.device_id)
|
||||
assert device
|
||||
assert device.configuration_url is None
|
||||
assert device.connections == {(dr.CONNECTION_NETWORK_MAC, "aa:bb:cc:dd:ee:ff")}
|
||||
assert device.entry_type is None
|
||||
assert device.hw_version is None
|
||||
assert device.identifiers == {(DOMAIN, "SA110405124500W00BS9")}
|
||||
assert device.manufacturer == "LaMetric Inc."
|
||||
assert device.name == "Frenck's LaMetric"
|
||||
assert device.sw_version == "2.2.2"
|
||||
|
||||
await hass.services.async_call(
|
||||
NUMBER_DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
{
|
||||
ATTR_ENTITY_ID: "number.frenck_s_lametric_brightness",
|
||||
ATTR_VALUE: 21,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_lametric.display.mock_calls) == 1
|
||||
mock_lametric.display.assert_called_once_with(brightness=21)
|
||||
|
||||
|
||||
async def test_volume(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
|
Loading…
x
Reference in New Issue
Block a user