mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Fix SleepIQ firmness number step and min values (#69757)
* fix sleepiq firmness number step and min values * add asserts for min/max/step attributes
This commit is contained in:
parent
fe6a4bfb1d
commit
836b051be9
@ -130,6 +130,7 @@ async def async_setup_entry(
|
||||
class SleepIQNumberEntity(SleepIQBedEntity, NumberEntity):
|
||||
"""Representation of a SleepIQ number entity."""
|
||||
|
||||
entity_description: SleepIQNumberEntityDescription
|
||||
_attr_icon = "mdi:bed"
|
||||
|
||||
def __init__(
|
||||
@ -140,7 +141,7 @@ class SleepIQNumberEntity(SleepIQBedEntity, NumberEntity):
|
||||
description: SleepIQNumberEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize the number."""
|
||||
self.description = description
|
||||
self.entity_description = description
|
||||
self.device = device
|
||||
|
||||
self._attr_name = description.get_name_fn(bed, device)
|
||||
@ -151,10 +152,10 @@ class SleepIQNumberEntity(SleepIQBedEntity, NumberEntity):
|
||||
@callback
|
||||
def _async_update_attrs(self) -> None:
|
||||
"""Update number attributes."""
|
||||
self._attr_value = float(self.description.value_fn(self.device))
|
||||
self._attr_value = float(self.entity_description.value_fn(self.device))
|
||||
|
||||
async def async_set_value(self, value: float) -> None:
|
||||
"""Set the number value."""
|
||||
await self.description.set_value_fn(self.device, int(value))
|
||||
await self.entity_description.set_value_fn(self.device, int(value))
|
||||
self._attr_value = value
|
||||
self.async_write_ha_state()
|
||||
|
@ -1,6 +1,12 @@
|
||||
"""The tests for SleepIQ number platform."""
|
||||
from homeassistant.components.number import DOMAIN
|
||||
from homeassistant.components.number.const import ATTR_VALUE, SERVICE_SET_VALUE
|
||||
from homeassistant.components.number.const import (
|
||||
ATTR_MAX,
|
||||
ATTR_MIN,
|
||||
ATTR_STEP,
|
||||
ATTR_VALUE,
|
||||
SERVICE_SET_VALUE,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME, ATTR_ICON
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
@ -28,6 +34,9 @@ async def test_firmness(hass, mock_asyncsleepiq):
|
||||
)
|
||||
assert state.state == "40.0"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:bed"
|
||||
assert state.attributes.get(ATTR_MIN) == 5
|
||||
assert state.attributes.get(ATTR_MAX) == 100
|
||||
assert state.attributes.get(ATTR_STEP) == 5
|
||||
assert (
|
||||
state.attributes.get(ATTR_FRIENDLY_NAME)
|
||||
== f"SleepNumber {BED_NAME} {SLEEPER_L_NAME} Firmness"
|
||||
@ -44,6 +53,9 @@ async def test_firmness(hass, mock_asyncsleepiq):
|
||||
)
|
||||
assert state.state == "80.0"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:bed"
|
||||
assert state.attributes.get(ATTR_MIN) == 5
|
||||
assert state.attributes.get(ATTR_MAX) == 100
|
||||
assert state.attributes.get(ATTR_STEP) == 5
|
||||
assert (
|
||||
state.attributes.get(ATTR_FRIENDLY_NAME)
|
||||
== f"SleepNumber {BED_NAME} {SLEEPER_R_NAME} Firmness"
|
||||
@ -78,6 +90,9 @@ async def test_actuators(hass, mock_asyncsleepiq):
|
||||
state = hass.states.get(f"number.sleepnumber_{BED_NAME_LOWER}_right_head_position")
|
||||
assert state.state == "60.0"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:bed"
|
||||
assert state.attributes.get(ATTR_MIN) == 0
|
||||
assert state.attributes.get(ATTR_MAX) == 100
|
||||
assert state.attributes.get(ATTR_STEP) == 1
|
||||
assert (
|
||||
state.attributes.get(ATTR_FRIENDLY_NAME)
|
||||
== f"SleepNumber {BED_NAME} Right Head Position"
|
||||
@ -92,6 +107,9 @@ async def test_actuators(hass, mock_asyncsleepiq):
|
||||
state = hass.states.get(f"number.sleepnumber_{BED_NAME_LOWER}_left_head_position")
|
||||
assert state.state == "50.0"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:bed"
|
||||
assert state.attributes.get(ATTR_MIN) == 0
|
||||
assert state.attributes.get(ATTR_MAX) == 100
|
||||
assert state.attributes.get(ATTR_STEP) == 1
|
||||
assert (
|
||||
state.attributes.get(ATTR_FRIENDLY_NAME)
|
||||
== f"SleepNumber {BED_NAME} Left Head Position"
|
||||
@ -106,6 +124,9 @@ async def test_actuators(hass, mock_asyncsleepiq):
|
||||
state = hass.states.get(f"number.sleepnumber_{BED_NAME_LOWER}_foot_position")
|
||||
assert state.state == "10.0"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:bed"
|
||||
assert state.attributes.get(ATTR_MIN) == 0
|
||||
assert state.attributes.get(ATTR_MAX) == 100
|
||||
assert state.attributes.get(ATTR_STEP) == 1
|
||||
assert (
|
||||
state.attributes.get(ATTR_FRIENDLY_NAME)
|
||||
== f"SleepNumber {BED_NAME} Foot Position"
|
||||
|
Loading…
x
Reference in New Issue
Block a user