mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Fix ozw dimming duration (#38254)
* Dimming duration fix Fixes #38068 - allows dimming duration to 7620 (default of 7621) * Forgot to commit my test updates * Added backwards compatibility with pre-150+ builds Added tests for backwards compatibility * Upped the build number cut off * Add check for major.minor version as well * Fix major.minor detection * Adjust variable name * Adjust version checking logic * Math is hard * Rename files, adjust test names * Update doc string
This commit is contained in:
parent
c29f412a70
commit
5fef9653a8
@ -140,27 +140,39 @@ class ZwaveLight(ZWaveDeviceEntity, LightEntity):
|
|||||||
def async_set_duration(self, **kwargs):
|
def async_set_duration(self, **kwargs):
|
||||||
"""Set the transition time for the brightness value.
|
"""Set the transition time for the brightness value.
|
||||||
|
|
||||||
Zwave Dimming Duration values:
|
Zwave Dimming Duration values now use seconds as an
|
||||||
0 = instant
|
integer (max: 7620 seconds or 127 mins)
|
||||||
0-127 = 1 second to 127 seconds
|
Build 1205 https://github.com/OpenZWave/open-zwave/commit/f81bc04
|
||||||
128-254 = 1 minute to 127 minutes
|
|
||||||
255 = factory default
|
|
||||||
"""
|
"""
|
||||||
if self.values.dimming_duration is None:
|
if self.values.dimming_duration is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
ozw_version = tuple(
|
||||||
|
int(x)
|
||||||
|
for x in self.values.primary.ozw_instance.get_status().openzwave_version.split(
|
||||||
|
"."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if ATTR_TRANSITION not in kwargs:
|
if ATTR_TRANSITION not in kwargs:
|
||||||
# no transition specified by user, use defaults
|
# no transition specified by user, use defaults
|
||||||
new_value = 255
|
new_value = 7621 # anything over 7620 uses the factory default
|
||||||
|
if ozw_version < (1, 6, 1205):
|
||||||
|
new_value = 255 # default for older version
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# transition specified by user, convert to zwave value
|
# transition specified by user
|
||||||
|
new_value = max(0, min(7620, kwargs[ATTR_TRANSITION]))
|
||||||
|
if ozw_version < (1, 6, 1205):
|
||||||
transition = kwargs[ATTR_TRANSITION]
|
transition = kwargs[ATTR_TRANSITION]
|
||||||
if transition <= 127:
|
if transition <= 127:
|
||||||
new_value = int(transition)
|
new_value = int(transition)
|
||||||
else:
|
else:
|
||||||
minutes = int(transition / 60)
|
minutes = int(transition / 60)
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Transition rounded to %d minutes for %s", minutes, self.entity_id
|
"Transition rounded to %d minutes for %s",
|
||||||
|
minutes,
|
||||||
|
self.entity_id,
|
||||||
)
|
)
|
||||||
new_value = minutes + 128
|
new_value = minutes + 128
|
||||||
|
|
||||||
|
@ -27,6 +27,12 @@ def light_data_fixture():
|
|||||||
return load_fixture("ozw/light_network_dump.csv")
|
return load_fixture("ozw/light_network_dump.csv")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(name="light_new_ozw_data", scope="session")
|
||||||
|
def light_new_ozw_data_fixture():
|
||||||
|
"""Load light dimmer MQTT data and return it."""
|
||||||
|
return load_fixture("ozw/light_new_ozw_network_dump.csv")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="light_no_rgb_data", scope="session")
|
@pytest.fixture(name="light_no_rgb_data", scope="session")
|
||||||
def light_no_rgb_data_fixture():
|
def light_no_rgb_data_fixture():
|
||||||
"""Load light dimmer MQTT data and return it."""
|
"""Load light dimmer MQTT data and return it."""
|
||||||
|
@ -514,3 +514,93 @@ async def test_wc_light(hass, light_wc_data, light_msg, light_rgb_msg, sent_mess
|
|||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == "on"
|
assert state.state == "on"
|
||||||
assert state.attributes["color_temp"] == 191
|
assert state.attributes["color_temp"] == 191
|
||||||
|
|
||||||
|
|
||||||
|
async def test_new_ozw_light(hass, light_new_ozw_data, light_msg, sent_messages):
|
||||||
|
"""Test setting up config entry."""
|
||||||
|
receive_message = await setup_ozw(hass, fixture=light_new_ozw_data)
|
||||||
|
|
||||||
|
# Test loaded only white LED support
|
||||||
|
state = hass.states.get("light.led_bulb_6_multi_colour_level")
|
||||||
|
assert state is not None
|
||||||
|
assert state.state == "off"
|
||||||
|
|
||||||
|
# Test turning on with new duration (newer openzwave)
|
||||||
|
new_transition = 4180
|
||||||
|
await hass.services.async_call(
|
||||||
|
"light",
|
||||||
|
"turn_on",
|
||||||
|
{
|
||||||
|
"entity_id": "light.led_bulb_6_multi_colour_level",
|
||||||
|
"transition": new_transition,
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert len(sent_messages) == 2
|
||||||
|
|
||||||
|
msg = sent_messages[-2]
|
||||||
|
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
||||||
|
assert msg["payload"] == {"Value": 4180, "ValueIDKey": 1407375551070225}
|
||||||
|
|
||||||
|
msg = sent_messages[-1]
|
||||||
|
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
||||||
|
assert msg["payload"] == {"Value": 255, "ValueIDKey": 659128337}
|
||||||
|
|
||||||
|
# Feedback on state
|
||||||
|
light_msg.decode()
|
||||||
|
light_msg.payload["Value"] = 255
|
||||||
|
light_msg.encode()
|
||||||
|
receive_message(light_msg)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
# Test turning off with new duration (newer openzwave)(new max)
|
||||||
|
await hass.services.async_call(
|
||||||
|
"light",
|
||||||
|
"turn_off",
|
||||||
|
{"entity_id": "light.led_bulb_6_multi_colour_level"},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert len(sent_messages) == 4
|
||||||
|
|
||||||
|
msg = sent_messages[-2]
|
||||||
|
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
||||||
|
assert msg["payload"] == {"Value": 7621, "ValueIDKey": 1407375551070225}
|
||||||
|
|
||||||
|
msg = sent_messages[-1]
|
||||||
|
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
||||||
|
assert msg["payload"] == {"Value": 0, "ValueIDKey": 659128337}
|
||||||
|
|
||||||
|
# Feedback on state
|
||||||
|
light_msg.decode()
|
||||||
|
light_msg.payload["Value"] = 0
|
||||||
|
light_msg.encode()
|
||||||
|
receive_message(light_msg)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
# Test turning on with new duration (newer openzwave)(factory default)
|
||||||
|
new_transition = 8000
|
||||||
|
await hass.services.async_call(
|
||||||
|
"light",
|
||||||
|
"turn_on",
|
||||||
|
{
|
||||||
|
"entity_id": "light.led_bulb_6_multi_colour_level",
|
||||||
|
"transition": new_transition,
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert len(sent_messages) == 6
|
||||||
|
|
||||||
|
msg = sent_messages[-2]
|
||||||
|
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
||||||
|
assert msg["payload"] == {"Value": 6553, "ValueIDKey": 1407375551070225}
|
||||||
|
|
||||||
|
msg = sent_messages[-1]
|
||||||
|
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
||||||
|
assert msg["payload"] == {"Value": 255, "ValueIDKey": 659128337}
|
||||||
|
|
||||||
|
# Feedback on state
|
||||||
|
light_msg.decode()
|
||||||
|
light_msg.payload["Value"] = 255
|
||||||
|
light_msg.encode()
|
||||||
|
receive_message(light_msg)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
55
tests/fixtures/ozw/light_new_ozw_network_dump.csv
vendored
Normal file
55
tests/fixtures/ozw/light_new_ozw_network_dump.csv
vendored
Normal file
File diff suppressed because one or more lines are too long
2
tests/fixtures/ozw/light_wc_network_dump.csv
vendored
2
tests/fixtures/ozw/light_wc_network_dump.csv
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user