Replace literals with consts in Govee Light Local tests (#143280)

This commit is contained in:
Abílio Costa 2025-04-19 20:11:36 +01:00 committed by GitHub
parent 7674f6b5aa
commit 626eb77060
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,14 +8,17 @@ import pytest
from homeassistant.components.govee_light_local.const import DOMAIN from homeassistant.components.govee_light_local.const import DOMAIN
from homeassistant.components.light import ( from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_BRIGHTNESS_PCT, ATTR_BRIGHTNESS_PCT,
ATTR_COLOR_TEMP_KELVIN, ATTR_COLOR_TEMP_KELVIN,
ATTR_EFFECT, ATTR_EFFECT,
ATTR_RGB_COLOR, ATTR_RGB_COLOR,
ATTR_SUPPORTED_COLOR_MODES, ATTR_SUPPORTED_COLOR_MODES,
DOMAIN as LIGHT_DOMAIN,
ColorMode, ColorMode,
) )
from homeassistant.config_entries import ConfigEntryState from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import SERVICE_TURN_OFF, SERVICE_TURN_ON
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from .conftest import DEFAULT_CAPABILITIES, SCENE_CAPABILITIES from .conftest import DEFAULT_CAPABILITIES, SCENE_CAPABILITIES
@ -205,8 +208,8 @@ async def test_light_on_off(hass: HomeAssistant, mock_govee_api: MagicMock) -> N
assert light.state == "off" assert light.state == "off"
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_on", SERVICE_TURN_ON,
{"entity_id": light.entity_id}, {"entity_id": light.entity_id},
blocking=True, blocking=True,
) )
@ -219,8 +222,8 @@ async def test_light_on_off(hass: HomeAssistant, mock_govee_api: MagicMock) -> N
# Turn off # Turn off
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_off", SERVICE_TURN_OFF,
{"entity_id": light.entity_id}, {"entity_id": light.entity_id},
blocking=True, blocking=True,
) )
@ -285,8 +288,8 @@ async def test_turn_on_call_order(
assert light.state == "off" assert light.state == "off"
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_on", SERVICE_TURN_ON,
{"entity_id": light.entity_id, ATTR_BRIGHTNESS_PCT: 50, attribute: value}, {"entity_id": light.entity_id, ATTR_BRIGHTNESS_PCT: 50, attribute: value},
blocking=True, blocking=True,
) )
@ -328,8 +331,8 @@ async def test_light_brightness(hass: HomeAssistant, mock_govee_api: MagicMock)
assert light.state == "off" assert light.state == "off"
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_on", SERVICE_TURN_ON,
{"entity_id": light.entity_id, "brightness_pct": 50}, {"entity_id": light.entity_id, "brightness_pct": 50},
blocking=True, blocking=True,
) )
@ -339,12 +342,12 @@ async def test_light_brightness(hass: HomeAssistant, mock_govee_api: MagicMock)
assert light is not None assert light is not None
assert light.state == "on" assert light.state == "on"
mock_govee_api.set_brightness.assert_awaited_with(mock_govee_api.devices[0], 50) mock_govee_api.set_brightness.assert_awaited_with(mock_govee_api.devices[0], 50)
assert light.attributes["brightness"] == 127 assert light.attributes[ATTR_BRIGHTNESS] == 127
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_on", SERVICE_TURN_ON,
{"entity_id": light.entity_id, "brightness": 255}, {"entity_id": light.entity_id, ATTR_BRIGHTNESS: 255},
blocking=True, blocking=True,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -352,13 +355,13 @@ async def test_light_brightness(hass: HomeAssistant, mock_govee_api: MagicMock)
light = hass.states.get("light.H615A") light = hass.states.get("light.H615A")
assert light is not None assert light is not None
assert light.state == "on" assert light.state == "on"
assert light.attributes["brightness"] == 255 assert light.attributes[ATTR_BRIGHTNESS] == 255
mock_govee_api.set_brightness.assert_awaited_with(mock_govee_api.devices[0], 100) mock_govee_api.set_brightness.assert_awaited_with(mock_govee_api.devices[0], 100)
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_on", SERVICE_TURN_ON,
{"entity_id": light.entity_id, "brightness": 255}, {"entity_id": light.entity_id, ATTR_BRIGHTNESS: 255},
blocking=True, blocking=True,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -366,7 +369,7 @@ async def test_light_brightness(hass: HomeAssistant, mock_govee_api: MagicMock)
light = hass.states.get("light.H615A") light = hass.states.get("light.H615A")
assert light is not None assert light is not None
assert light.state == "on" assert light.state == "on"
assert light.attributes["brightness"] == 255 assert light.attributes[ATTR_BRIGHTNESS] == 255
mock_govee_api.set_brightness.assert_awaited_with(mock_govee_api.devices[0], 100) mock_govee_api.set_brightness.assert_awaited_with(mock_govee_api.devices[0], 100)
@ -395,9 +398,9 @@ async def test_light_color(hass: HomeAssistant, mock_govee_api: MagicMock) -> No
assert light.state == "off" assert light.state == "off"
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_on", SERVICE_TURN_ON,
{"entity_id": light.entity_id, "rgb_color": [100, 255, 50]}, {"entity_id": light.entity_id, ATTR_RGB_COLOR: [100, 255, 50]},
blocking=True, blocking=True,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -405,7 +408,7 @@ async def test_light_color(hass: HomeAssistant, mock_govee_api: MagicMock) -> No
light = hass.states.get("light.H615A") light = hass.states.get("light.H615A")
assert light is not None assert light is not None
assert light.state == "on" assert light.state == "on"
assert light.attributes["rgb_color"] == (100, 255, 50) assert light.attributes[ATTR_RGB_COLOR] == (100, 255, 50)
assert light.attributes["color_mode"] == ColorMode.RGB assert light.attributes["color_mode"] == ColorMode.RGB
mock_govee_api.set_color.assert_awaited_with( mock_govee_api.set_color.assert_awaited_with(
@ -413,8 +416,8 @@ async def test_light_color(hass: HomeAssistant, mock_govee_api: MagicMock) -> No
) )
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_on", SERVICE_TURN_ON,
{"entity_id": light.entity_id, "kelvin": 4400}, {"entity_id": light.entity_id, "kelvin": 4400},
blocking=True, blocking=True,
) )
@ -457,9 +460,9 @@ async def test_scene_on(hass: HomeAssistant, mock_govee_api: MagicMock) -> None:
assert light.state == "off" assert light.state == "off"
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_on", SERVICE_TURN_ON,
{"entity_id": light.entity_id, "effect": "sunrise"}, {"entity_id": light.entity_id, ATTR_EFFECT: "sunrise"},
blocking=True, blocking=True,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -467,7 +470,7 @@ async def test_scene_on(hass: HomeAssistant, mock_govee_api: MagicMock) -> None:
light = hass.states.get("light.H615A") light = hass.states.get("light.H615A")
assert light is not None assert light is not None
assert light.state == "on" assert light.state == "on"
assert light.attributes["effect"] == "sunrise" assert light.attributes[ATTR_EFFECT] == "sunrise"
mock_govee_api.turn_on_off.assert_awaited_with(mock_govee_api.devices[0], True) mock_govee_api.turn_on_off.assert_awaited_with(mock_govee_api.devices[0], True)
@ -501,16 +504,16 @@ async def test_scene_restore_rgb(
# Set initial color # Set initial color
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_on", SERVICE_TURN_ON,
{"entity_id": light.entity_id, "rgb_color": initial_color}, {"entity_id": light.entity_id, ATTR_RGB_COLOR: initial_color},
blocking=True, blocking=True,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_on", SERVICE_TURN_ON,
{"entity_id": light.entity_id, "brightness": 255}, {"entity_id": light.entity_id, ATTR_BRIGHTNESS: 255},
blocking=True, blocking=True,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -518,15 +521,15 @@ async def test_scene_restore_rgb(
light = hass.states.get("light.H615A") light = hass.states.get("light.H615A")
assert light is not None assert light is not None
assert light.state == "on" assert light.state == "on"
assert light.attributes["rgb_color"] == initial_color assert light.attributes[ATTR_RGB_COLOR] == initial_color
assert light.attributes["brightness"] == 255 assert light.attributes[ATTR_BRIGHTNESS] == 255
mock_govee_api.turn_on_off.assert_awaited_with(mock_govee_api.devices[0], True) mock_govee_api.turn_on_off.assert_awaited_with(mock_govee_api.devices[0], True)
# Activate scene # Activate scene
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_on", SERVICE_TURN_ON,
{"entity_id": light.entity_id, "effect": "sunrise"}, {"entity_id": light.entity_id, ATTR_EFFECT: "sunrise"},
blocking=True, blocking=True,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -534,14 +537,14 @@ async def test_scene_restore_rgb(
light = hass.states.get("light.H615A") light = hass.states.get("light.H615A")
assert light is not None assert light is not None
assert light.state == "on" assert light.state == "on"
assert light.attributes["effect"] == "sunrise" assert light.attributes[ATTR_EFFECT] == "sunrise"
mock_govee_api.turn_on_off.assert_awaited_with(mock_govee_api.devices[0], True) mock_govee_api.turn_on_off.assert_awaited_with(mock_govee_api.devices[0], True)
# Deactivate scene # Deactivate scene
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_on", SERVICE_TURN_ON,
{"entity_id": light.entity_id, "effect": "none"}, {"entity_id": light.entity_id, ATTR_EFFECT: "none"},
blocking=True, blocking=True,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -549,9 +552,9 @@ async def test_scene_restore_rgb(
light = hass.states.get("light.H615A") light = hass.states.get("light.H615A")
assert light is not None assert light is not None
assert light.state == "on" assert light.state == "on"
assert light.attributes["effect"] is None assert light.attributes[ATTR_EFFECT] is None
assert light.attributes["rgb_color"] == initial_color assert light.attributes[ATTR_RGB_COLOR] == initial_color
assert light.attributes["brightness"] == 255 assert light.attributes[ATTR_BRIGHTNESS] == 255
async def test_scene_restore_temperature( async def test_scene_restore_temperature(
@ -584,8 +587,8 @@ async def test_scene_restore_temperature(
# Set initial color # Set initial color
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_on", SERVICE_TURN_ON,
{"entity_id": light.entity_id, "color_temp_kelvin": initial_color}, {"entity_id": light.entity_id, "color_temp_kelvin": initial_color},
blocking=True, blocking=True,
) )
@ -599,9 +602,9 @@ async def test_scene_restore_temperature(
# Activate scene # Activate scene
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_on", SERVICE_TURN_ON,
{"entity_id": light.entity_id, "effect": "sunrise"}, {"entity_id": light.entity_id, ATTR_EFFECT: "sunrise"},
blocking=True, blocking=True,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -609,14 +612,14 @@ async def test_scene_restore_temperature(
light = hass.states.get("light.H615A") light = hass.states.get("light.H615A")
assert light is not None assert light is not None
assert light.state == "on" assert light.state == "on"
assert light.attributes["effect"] == "sunrise" assert light.attributes[ATTR_EFFECT] == "sunrise"
mock_govee_api.set_scene.assert_awaited_with(mock_govee_api.devices[0], "sunrise") mock_govee_api.set_scene.assert_awaited_with(mock_govee_api.devices[0], "sunrise")
# Deactivate scene # Deactivate scene
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_on", SERVICE_TURN_ON,
{"entity_id": light.entity_id, "effect": "none"}, {"entity_id": light.entity_id, ATTR_EFFECT: "none"},
blocking=True, blocking=True,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -624,7 +627,7 @@ async def test_scene_restore_temperature(
light = hass.states.get("light.H615A") light = hass.states.get("light.H615A")
assert light is not None assert light is not None
assert light.state == "on" assert light.state == "on"
assert light.attributes["effect"] is None assert light.attributes[ATTR_EFFECT] is None
assert light.attributes["color_temp_kelvin"] == initial_color assert light.attributes["color_temp_kelvin"] == initial_color
@ -656,16 +659,16 @@ async def test_scene_none(hass: HomeAssistant, mock_govee_api: MagicMock) -> Non
# Set initial color # Set initial color
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_on", SERVICE_TURN_ON,
{"entity_id": light.entity_id, "rgb_color": initial_color}, {"entity_id": light.entity_id, ATTR_RGB_COLOR: initial_color},
blocking=True, blocking=True,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_on", SERVICE_TURN_ON,
{"entity_id": light.entity_id, "brightness": 255}, {"entity_id": light.entity_id, ATTR_BRIGHTNESS: 255},
blocking=True, blocking=True,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -673,21 +676,20 @@ async def test_scene_none(hass: HomeAssistant, mock_govee_api: MagicMock) -> Non
light = hass.states.get("light.H615A") light = hass.states.get("light.H615A")
assert light is not None assert light is not None
assert light.state == "on" assert light.state == "on"
assert light.attributes["rgb_color"] == initial_color assert light.attributes[ATTR_RGB_COLOR] == initial_color
assert light.attributes["brightness"] == 255 assert light.attributes[ATTR_BRIGHTNESS] == 255
mock_govee_api.turn_on_off.assert_awaited_with(mock_govee_api.devices[0], True) mock_govee_api.turn_on_off.assert_awaited_with(mock_govee_api.devices[0], True)
# Activate scene # Activate scene
await hass.services.async_call( await hass.services.async_call(
"light", LIGHT_DOMAIN,
"turn_on", SERVICE_TURN_ON,
{"entity_id": light.entity_id, "effect": "none"}, {"entity_id": light.entity_id, ATTR_EFFECT: "none"},
blocking=True, blocking=True,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
light = hass.states.get("light.H615A") light = hass.states.get("light.H615A")
assert light is not None assert light is not None
assert light.state == "on" assert light.state == "on"
assert light.attributes["effect"] is None assert light.attributes[ATTR_EFFECT] is None
mock_govee_api.set_scene.assert_not_called() mock_govee_api.set_scene.assert_not_called()