mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Set Entity._platform_state in google_assistant tests (#147892)
This commit is contained in:
parent
c71dbd9d4d
commit
66308a848a
@ -47,6 +47,7 @@ from homeassistant.helpers import (
|
|||||||
entity_platform,
|
entity_platform,
|
||||||
entity_registry as er,
|
entity_registry as er,
|
||||||
)
|
)
|
||||||
|
from homeassistant.helpers.entity import EntityPlatformState
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from . import BASIC_CONFIG, MockConfig
|
from . import BASIC_CONFIG, MockConfig
|
||||||
@ -160,6 +161,7 @@ async def test_sync_message(hass: HomeAssistant, registries) -> None:
|
|||||||
light.entity_id = "light.demo_light"
|
light.entity_id = "light.demo_light"
|
||||||
light._attr_device_info = None
|
light._attr_device_info = None
|
||||||
light._attr_name = "Demo Light"
|
light._attr_name = "Demo Light"
|
||||||
|
light._platform_state = EntityPlatformState.ADDED
|
||||||
light.async_write_ha_state()
|
light.async_write_ha_state()
|
||||||
|
|
||||||
# This should not show up in the sync request
|
# This should not show up in the sync request
|
||||||
@ -306,6 +308,7 @@ async def test_sync_in_area(area_on_device, hass: HomeAssistant, registries) ->
|
|||||||
light.entity_id = entity.entity_id
|
light.entity_id = entity.entity_id
|
||||||
light._attr_device_info = None
|
light._attr_device_info = None
|
||||||
light._attr_name = "Demo Light"
|
light._attr_name = "Demo Light"
|
||||||
|
light._platform_state = EntityPlatformState.ADDED
|
||||||
light.async_write_ha_state()
|
light.async_write_ha_state()
|
||||||
|
|
||||||
config = MockConfig(should_expose=lambda _: True, entity_config={})
|
config = MockConfig(should_expose=lambda _: True, entity_config={})
|
||||||
@ -402,6 +405,7 @@ async def test_query_message(hass: HomeAssistant) -> None:
|
|||||||
light.entity_id = "light.demo_light"
|
light.entity_id = "light.demo_light"
|
||||||
light._attr_device_info = None
|
light._attr_device_info = None
|
||||||
light._attr_name = "Demo Light"
|
light._attr_name = "Demo Light"
|
||||||
|
light._platform_state = EntityPlatformState.ADDED
|
||||||
light.async_write_ha_state()
|
light.async_write_ha_state()
|
||||||
|
|
||||||
light2 = DemoLight(
|
light2 = DemoLight(
|
||||||
@ -412,6 +416,7 @@ async def test_query_message(hass: HomeAssistant) -> None:
|
|||||||
light2.entity_id = "light.another_light"
|
light2.entity_id = "light.another_light"
|
||||||
light2._attr_device_info = None
|
light2._attr_device_info = None
|
||||||
light2._attr_name = "Another Light"
|
light2._attr_name = "Another Light"
|
||||||
|
light2._platform_state = EntityPlatformState.ADDED
|
||||||
light2.async_write_ha_state()
|
light2.async_write_ha_state()
|
||||||
|
|
||||||
light3 = DemoLight(None, "Color temp Light", state=True, ct=2500, brightness=200)
|
light3 = DemoLight(None, "Color temp Light", state=True, ct=2500, brightness=200)
|
||||||
@ -420,6 +425,7 @@ async def test_query_message(hass: HomeAssistant) -> None:
|
|||||||
light3.entity_id = "light.color_temp_light"
|
light3.entity_id = "light.color_temp_light"
|
||||||
light3._attr_device_info = None
|
light3._attr_device_info = None
|
||||||
light3._attr_name = "Color temp Light"
|
light3._attr_name = "Color temp Light"
|
||||||
|
light3._platform_state = EntityPlatformState.ADDED
|
||||||
light3.async_write_ha_state()
|
light3.async_write_ha_state()
|
||||||
|
|
||||||
events = async_capture_events(hass, EVENT_QUERY_RECEIVED)
|
events = async_capture_events(hass, EVENT_QUERY_RECEIVED)
|
||||||
@ -909,6 +915,7 @@ async def test_unavailable_state_does_sync(hass: HomeAssistant) -> None:
|
|||||||
light._available = False
|
light._available = False
|
||||||
light._attr_device_info = None
|
light._attr_device_info = None
|
||||||
light._attr_name = "Demo Light"
|
light._attr_name = "Demo Light"
|
||||||
|
light._platform_state = EntityPlatformState.ADDED
|
||||||
light.async_write_ha_state()
|
light.async_write_ha_state()
|
||||||
|
|
||||||
events = async_capture_events(hass, EVENT_SYNC_RECEIVED)
|
events = async_capture_events(hass, EVENT_SYNC_RECEIVED)
|
||||||
@ -994,19 +1001,20 @@ async def test_device_class_switch(
|
|||||||
hass: HomeAssistant, device_class, google_type
|
hass: HomeAssistant, device_class, google_type
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that a cover entity syncs to the correct device type."""
|
"""Test that a cover entity syncs to the correct device type."""
|
||||||
sensor = DemoSwitch(
|
switch = DemoSwitch(
|
||||||
None,
|
None,
|
||||||
"Demo Sensor",
|
"Demo switch",
|
||||||
state=False,
|
state=False,
|
||||||
assumed=False,
|
assumed=False,
|
||||||
device_class=device_class,
|
device_class=device_class,
|
||||||
)
|
)
|
||||||
sensor.hass = hass
|
switch.hass = hass
|
||||||
sensor.platform = MockEntityPlatform(hass)
|
switch.platform = MockEntityPlatform(hass)
|
||||||
sensor.entity_id = "switch.demo_sensor"
|
switch.entity_id = "switch.demo_switch"
|
||||||
sensor._attr_device_info = None
|
switch._attr_device_info = None
|
||||||
sensor._attr_name = "Demo Sensor"
|
switch._attr_name = "Demo Switch"
|
||||||
sensor.async_write_ha_state()
|
switch._platform_state = EntityPlatformState.ADDED
|
||||||
|
switch.async_write_ha_state()
|
||||||
|
|
||||||
result = await sh.async_handle_message(
|
result = await sh.async_handle_message(
|
||||||
hass,
|
hass,
|
||||||
@ -1024,8 +1032,8 @@ async def test_device_class_switch(
|
|||||||
"devices": [
|
"devices": [
|
||||||
{
|
{
|
||||||
"attributes": {},
|
"attributes": {},
|
||||||
"id": "switch.demo_sensor",
|
"id": "switch.demo_switch",
|
||||||
"name": {"name": "Demo Sensor"},
|
"name": {"name": "Demo Switch"},
|
||||||
"traits": ["action.devices.traits.OnOff"],
|
"traits": ["action.devices.traits.OnOff"],
|
||||||
"type": google_type,
|
"type": google_type,
|
||||||
"willReportState": False,
|
"willReportState": False,
|
||||||
@ -1049,15 +1057,16 @@ async def test_device_class_binary_sensor(
|
|||||||
hass: HomeAssistant, device_class, google_type
|
hass: HomeAssistant, device_class, google_type
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that a binary entity syncs to the correct device type."""
|
"""Test that a binary entity syncs to the correct device type."""
|
||||||
sensor = DemoBinarySensor(
|
binary_sensor = DemoBinarySensor(
|
||||||
None, "Demo Sensor", state=False, device_class=device_class
|
None, "Demo Binary Sensor", state=False, device_class=device_class
|
||||||
)
|
)
|
||||||
sensor.hass = hass
|
binary_sensor.hass = hass
|
||||||
sensor.platform = MockEntityPlatform(hass)
|
binary_sensor.platform = MockEntityPlatform(hass)
|
||||||
sensor.entity_id = "binary_sensor.demo_sensor"
|
binary_sensor.entity_id = "binary_sensor.demo_binary_sensor"
|
||||||
sensor._attr_device_info = None
|
binary_sensor._attr_device_info = None
|
||||||
sensor._attr_name = "Demo Sensor"
|
binary_sensor._attr_name = "Demo Binary Sensor"
|
||||||
sensor.async_write_ha_state()
|
binary_sensor._platform_state = EntityPlatformState.ADDED
|
||||||
|
binary_sensor.async_write_ha_state()
|
||||||
|
|
||||||
result = await sh.async_handle_message(
|
result = await sh.async_handle_message(
|
||||||
hass,
|
hass,
|
||||||
@ -1078,8 +1087,8 @@ async def test_device_class_binary_sensor(
|
|||||||
"queryOnlyOpenClose": True,
|
"queryOnlyOpenClose": True,
|
||||||
"discreteOnlyOpenClose": True,
|
"discreteOnlyOpenClose": True,
|
||||||
},
|
},
|
||||||
"id": "binary_sensor.demo_sensor",
|
"id": "binary_sensor.demo_binary_sensor",
|
||||||
"name": {"name": "Demo Sensor"},
|
"name": {"name": "Demo Binary Sensor"},
|
||||||
"traits": ["action.devices.traits.OpenClose"],
|
"traits": ["action.devices.traits.OpenClose"],
|
||||||
"type": google_type,
|
"type": google_type,
|
||||||
"willReportState": False,
|
"willReportState": False,
|
||||||
@ -1106,13 +1115,14 @@ async def test_device_class_cover(
|
|||||||
hass: HomeAssistant, device_class, google_type
|
hass: HomeAssistant, device_class, google_type
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that a cover entity syncs to the correct device type."""
|
"""Test that a cover entity syncs to the correct device type."""
|
||||||
sensor = DemoCover(None, hass, "Demo Sensor", device_class=device_class)
|
cover = DemoCover(None, hass, "Demo Cover", device_class=device_class)
|
||||||
sensor.hass = hass
|
cover.hass = hass
|
||||||
sensor.platform = MockEntityPlatform(hass)
|
cover.platform = MockEntityPlatform(hass)
|
||||||
sensor.entity_id = "cover.demo_sensor"
|
cover.entity_id = "cover.demo_cover"
|
||||||
sensor._attr_device_info = None
|
cover._attr_device_info = None
|
||||||
sensor._attr_name = "Demo Sensor"
|
cover._attr_name = "Demo Cover"
|
||||||
sensor.async_write_ha_state()
|
cover._platform_state = EntityPlatformState.ADDED
|
||||||
|
cover.async_write_ha_state()
|
||||||
|
|
||||||
result = await sh.async_handle_message(
|
result = await sh.async_handle_message(
|
||||||
hass,
|
hass,
|
||||||
@ -1130,8 +1140,8 @@ async def test_device_class_cover(
|
|||||||
"devices": [
|
"devices": [
|
||||||
{
|
{
|
||||||
"attributes": {"discreteOnlyOpenClose": True},
|
"attributes": {"discreteOnlyOpenClose": True},
|
||||||
"id": "cover.demo_sensor",
|
"id": "cover.demo_cover",
|
||||||
"name": {"name": "Demo Sensor"},
|
"name": {"name": "Demo Cover"},
|
||||||
"traits": [
|
"traits": [
|
||||||
"action.devices.traits.StartStop",
|
"action.devices.traits.StartStop",
|
||||||
"action.devices.traits.OpenClose",
|
"action.devices.traits.OpenClose",
|
||||||
@ -1157,11 +1167,12 @@ async def test_device_media_player(
|
|||||||
hass: HomeAssistant, device_class, google_type
|
hass: HomeAssistant, device_class, google_type
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that a binary entity syncs to the correct device type."""
|
"""Test that a binary entity syncs to the correct device type."""
|
||||||
sensor = AbstractDemoPlayer("Demo", device_class=device_class)
|
media_player = AbstractDemoPlayer("Demo", device_class=device_class)
|
||||||
sensor.hass = hass
|
media_player.hass = hass
|
||||||
sensor.platform = MockEntityPlatform(hass)
|
media_player.platform = MockEntityPlatform(hass)
|
||||||
sensor.entity_id = "media_player.demo"
|
media_player.entity_id = "media_player.demo"
|
||||||
sensor.async_write_ha_state()
|
media_player._platform_state = EntityPlatformState.ADDED
|
||||||
|
media_player.async_write_ha_state()
|
||||||
|
|
||||||
result = await sh.async_handle_message(
|
result = await sh.async_handle_message(
|
||||||
hass,
|
hass,
|
||||||
@ -1182,8 +1193,8 @@ async def test_device_media_player(
|
|||||||
"supportActivityState": True,
|
"supportActivityState": True,
|
||||||
"supportPlaybackState": True,
|
"supportPlaybackState": True,
|
||||||
},
|
},
|
||||||
"id": sensor.entity_id,
|
"id": media_player.entity_id,
|
||||||
"name": {"name": sensor.name},
|
"name": {"name": media_player.name},
|
||||||
"traits": [
|
"traits": [
|
||||||
"action.devices.traits.OnOff",
|
"action.devices.traits.OnOff",
|
||||||
"action.devices.traits.MediaState",
|
"action.devices.traits.MediaState",
|
||||||
@ -1455,6 +1466,7 @@ async def test_sync_message_recovery(
|
|||||||
light.entity_id = "light.demo_light"
|
light.entity_id = "light.demo_light"
|
||||||
light._attr_device_info = None
|
light._attr_device_info = None
|
||||||
light._attr_name = "Demo Light"
|
light._attr_name = "Demo Light"
|
||||||
|
light._platform_state = EntityPlatformState.ADDED
|
||||||
light.async_write_ha_state()
|
light.async_write_ha_state()
|
||||||
|
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user