parent
7127492767
commit
4c4e5f3fa9
|
@ -23,6 +23,7 @@ COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM = [
|
|||
"media_player",
|
||||
"sensor",
|
||||
"switch",
|
||||
"vacuum",
|
||||
"water_heater",
|
||||
]
|
||||
|
||||
|
|
|
@ -44,9 +44,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
effect_list=LIGHT_EFFECT_LIST,
|
||||
effect=LIGHT_EFFECT_LIST[0],
|
||||
),
|
||||
DemoLight(
|
||||
"light_2", "Ceiling Lights", True, True, LIGHT_COLORS[0], LIGHT_TEMPS[1]
|
||||
),
|
||||
DemoLight("light_2", "Ceiling Lights", True, True, ct=LIGHT_TEMPS[1]),
|
||||
DemoLight(
|
||||
"light_3", "Kitchen Lights", True, True, LIGHT_COLORS[1], LIGHT_TEMPS[0]
|
||||
),
|
||||
|
@ -86,6 +84,10 @@ class DemoLight(Light):
|
|||
self._effect_list = effect_list
|
||||
self._effect = effect
|
||||
self._available = True
|
||||
if ct is not None and hs_color is None:
|
||||
self._color_mode = "ct"
|
||||
else:
|
||||
self._color_mode = "hs"
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
|
@ -128,12 +130,16 @@ class DemoLight(Light):
|
|||
@property
|
||||
def hs_color(self) -> tuple:
|
||||
"""Return the hs color value."""
|
||||
return self._hs_color
|
||||
if self._color_mode == "hs":
|
||||
return self._hs_color
|
||||
return None
|
||||
|
||||
@property
|
||||
def color_temp(self) -> int:
|
||||
"""Return the CT color temperature."""
|
||||
return self._ct
|
||||
if self._color_mode == "ct":
|
||||
return self._ct
|
||||
return None
|
||||
|
||||
@property
|
||||
def white_value(self) -> int:
|
||||
|
@ -165,9 +171,11 @@ class DemoLight(Light):
|
|||
self._state = True
|
||||
|
||||
if ATTR_HS_COLOR in kwargs:
|
||||
self._color_mode = "hs"
|
||||
self._hs_color = kwargs[ATTR_HS_COLOR]
|
||||
|
||||
if ATTR_COLOR_TEMP in kwargs:
|
||||
self._color_mode = "ct"
|
||||
self._ct = kwargs[ATTR_COLOR_TEMP]
|
||||
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
|
|
|
@ -10,7 +10,14 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
async_add_entities(
|
||||
[
|
||||
DemoSwitch("swith1", "Decorative Lights", True, None, True),
|
||||
DemoSwitch("swith2", "AC", False, "mdi:air-conditioner", False),
|
||||
DemoSwitch(
|
||||
"swith2",
|
||||
"AC",
|
||||
False,
|
||||
"mdi:air-conditioner",
|
||||
False,
|
||||
device_class="outlet",
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
@ -78,12 +78,12 @@ DEMO_VACUUM_STATE = "5_Fifth_floor"
|
|||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the Demo config entry."""
|
||||
setup_platform(hass, {}, async_add_entities)
|
||||
await async_setup_platform(hass, {}, async_add_entities)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the Demo vacuums."""
|
||||
add_entities(
|
||||
async_add_entities(
|
||||
[
|
||||
DemoVacuum(DEMO_VACUUM_COMPLETE, SUPPORT_ALL_SERVICES),
|
||||
DemoVacuum(DEMO_VACUUM_MOST, SUPPORT_MOST_SERVICES),
|
||||
|
|
|
@ -92,7 +92,7 @@ DEMO_DEVICES = [
|
|||
"id": "switch.ac",
|
||||
"name": {"name": "AC"},
|
||||
"traits": ["action.devices.traits.OnOff"],
|
||||
"type": "action.devices.types.SWITCH",
|
||||
"type": "action.devices.types.OUTLET",
|
||||
"willReportState": False,
|
||||
},
|
||||
{
|
||||
|
|
|
@ -175,12 +175,12 @@ async def test_query_request(hass_fixture, assistant_client, auth_header):
|
|||
assert devices["light.bed_light"]["on"] is False
|
||||
assert devices["light.ceiling_lights"]["on"] is True
|
||||
assert devices["light.ceiling_lights"]["brightness"] == 70
|
||||
assert devices["light.ceiling_lights"]["color"]["temperatureK"] == 2631
|
||||
assert devices["light.kitchen_lights"]["color"]["spectrumHsv"] == {
|
||||
"hue": 345,
|
||||
"saturation": 0.75,
|
||||
"value": 0.7058823529411765,
|
||||
}
|
||||
assert devices["light.kitchen_lights"]["color"]["temperatureK"] == 4166
|
||||
assert devices["media_player.lounge_room"]["on"] is True
|
||||
|
||||
|
||||
|
@ -372,7 +372,6 @@ async def test_execute_request(hass_fixture, assistant_client, auth_header):
|
|||
|
||||
bed = hass_fixture.states.get("light.bed_light")
|
||||
assert bed.attributes.get(light.ATTR_COLOR_TEMP) == 212
|
||||
assert bed.attributes.get(light.ATTR_RGB_COLOR) == (0, 255, 0)
|
||||
|
||||
assert hass_fixture.states.get("switch.decorative_lights").state == "off"
|
||||
|
||||
|
|
|
@ -203,6 +203,11 @@ async def test_query_message(hass):
|
|||
light2.entity_id = "light.another_light"
|
||||
await light2.async_update_ha_state()
|
||||
|
||||
light3 = DemoLight(None, "Color temp Light", state=True, ct=400, brightness=200)
|
||||
light3.hass = hass
|
||||
light3.entity_id = "light.color_temp_light"
|
||||
await light3.async_update_ha_state()
|
||||
|
||||
events = []
|
||||
hass.bus.async_listen(EVENT_QUERY_RECEIVED, events.append)
|
||||
|
||||
|
@ -219,6 +224,7 @@ async def test_query_message(hass):
|
|||
"devices": [
|
||||
{"id": "light.demo_light"},
|
||||
{"id": "light.another_light"},
|
||||
{"id": "light.color_temp_light"},
|
||||
{"id": "light.non_existing"},
|
||||
]
|
||||
},
|
||||
|
@ -244,14 +250,19 @@ async def test_query_message(hass):
|
|||
"saturation": 0.75,
|
||||
"value": 0.3058823529411765,
|
||||
},
|
||||
"temperatureK": 2500,
|
||||
},
|
||||
},
|
||||
"light.color_temp_light": {
|
||||
"on": True,
|
||||
"online": True,
|
||||
"brightness": 78,
|
||||
"color": {"temperatureK": 2500},
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
assert len(events) == 3
|
||||
assert len(events) == 4
|
||||
assert events[0].event_type == EVENT_QUERY_RECEIVED
|
||||
assert events[0].data == {
|
||||
"request_id": REQ_ID,
|
||||
|
@ -266,6 +277,12 @@ async def test_query_message(hass):
|
|||
}
|
||||
assert events[2].event_type == EVENT_QUERY_RECEIVED
|
||||
assert events[2].data == {
|
||||
"request_id": REQ_ID,
|
||||
"entity_id": "light.color_temp_light",
|
||||
"source": "cloud",
|
||||
}
|
||||
assert events[3].event_type == EVENT_QUERY_RECEIVED
|
||||
assert events[3].data == {
|
||||
"request_id": REQ_ID,
|
||||
"entity_id": "light.non_existing",
|
||||
"source": "cloud",
|
||||
|
@ -301,6 +318,7 @@ async def test_execute(hass):
|
|||
"devices": [
|
||||
{"id": "light.non_existing"},
|
||||
{"id": "light.ceiling_lights"},
|
||||
{"id": "light.kitchen_lights"},
|
||||
],
|
||||
"execution": [
|
||||
{
|
||||
|
@ -321,6 +339,8 @@ async def test_execute(hass):
|
|||
const.SOURCE_CLOUD,
|
||||
)
|
||||
|
||||
print(result)
|
||||
|
||||
assert result == {
|
||||
"requestId": REQ_ID,
|
||||
"payload": {
|
||||
|
@ -333,17 +353,26 @@ async def test_execute(hass):
|
|||
{
|
||||
"ids": ["light.ceiling_lights"],
|
||||
"status": "SUCCESS",
|
||||
"states": {
|
||||
"on": True,
|
||||
"online": True,
|
||||
"brightness": 20,
|
||||
"color": {"temperatureK": 2631},
|
||||
},
|
||||
},
|
||||
{
|
||||
"ids": ["light.kitchen_lights"],
|
||||
"status": "SUCCESS",
|
||||
"states": {
|
||||
"on": True,
|
||||
"online": True,
|
||||
"brightness": 20,
|
||||
"color": {
|
||||
"spectrumHsv": {
|
||||
"hue": 56,
|
||||
"saturation": 0.86,
|
||||
"hue": 345,
|
||||
"saturation": 0.75,
|
||||
"value": 0.2,
|
||||
},
|
||||
"temperatureK": 2631,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -351,7 +380,7 @@ async def test_execute(hass):
|
|||
},
|
||||
}
|
||||
|
||||
assert len(events) == 4
|
||||
assert len(events) == 6
|
||||
assert events[0].event_type == EVENT_COMMAND_RECEIVED
|
||||
assert events[0].data == {
|
||||
"request_id": REQ_ID,
|
||||
|
@ -392,21 +421,54 @@ async def test_execute(hass):
|
|||
},
|
||||
"source": "cloud",
|
||||
}
|
||||
assert events[4].event_type == EVENT_COMMAND_RECEIVED
|
||||
assert events[4].data == {
|
||||
"request_id": REQ_ID,
|
||||
"entity_id": "light.kitchen_lights",
|
||||
"execution": {
|
||||
"command": "action.devices.commands.OnOff",
|
||||
"params": {"on": True},
|
||||
},
|
||||
"source": "cloud",
|
||||
}
|
||||
assert events[5].event_type == EVENT_COMMAND_RECEIVED
|
||||
assert events[5].data == {
|
||||
"request_id": REQ_ID,
|
||||
"entity_id": "light.kitchen_lights",
|
||||
"execution": {
|
||||
"command": "action.devices.commands.BrightnessAbsolute",
|
||||
"params": {"brightness": 20},
|
||||
},
|
||||
"source": "cloud",
|
||||
}
|
||||
|
||||
assert len(service_events) == 2
|
||||
assert len(service_events) == 4
|
||||
assert service_events[0].data == {
|
||||
"domain": "light",
|
||||
"service": "turn_on",
|
||||
"service_data": {"entity_id": "light.ceiling_lights"},
|
||||
}
|
||||
assert service_events[0].context == events[2].context
|
||||
assert service_events[1].data == {
|
||||
"domain": "light",
|
||||
"service": "turn_on",
|
||||
"service_data": {"brightness_pct": 20, "entity_id": "light.ceiling_lights"},
|
||||
}
|
||||
assert service_events[0].context == events[2].context
|
||||
assert service_events[1].context == events[2].context
|
||||
assert service_events[1].context == events[3].context
|
||||
assert service_events[2].data == {
|
||||
"domain": "light",
|
||||
"service": "turn_on",
|
||||
"service_data": {"entity_id": "light.kitchen_lights"},
|
||||
}
|
||||
assert service_events[3].data == {
|
||||
"domain": "light",
|
||||
"service": "turn_on",
|
||||
"service_data": {"brightness_pct": 20, "entity_id": "light.kitchen_lights"},
|
||||
}
|
||||
assert service_events[2].context == events[4].context
|
||||
assert service_events[3].context == events[4].context
|
||||
assert service_events[3].context == events[5].context
|
||||
|
||||
|
||||
async def test_raising_error_trait(hass):
|
||||
|
|
|
@ -229,7 +229,7 @@ async def test_emulated_color_temp_group(hass):
|
|||
state = hass.states.get("light.ceiling_lights")
|
||||
assert state.state == "on"
|
||||
assert state.attributes["color_temp"] == 200
|
||||
assert "hs_color" in state.attributes.keys()
|
||||
assert "hs_color" not in state.attributes.keys()
|
||||
|
||||
state = hass.states.get("light.kitchen_lights")
|
||||
assert state.state == "on"
|
||||
|
|
Loading…
Reference in New Issue