mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Add Cover platform to Teslemetry (#117340)
* Add cover * Test coverage * Json lint * Apply suggestions from code review Co-authored-by: G Johansson <goran.johansson@shiftit.se> * Update tests * Fix features * Update snapshot from fixture * Apply suggestions from code review --------- Co-authored-by: G Johansson <goran.johansson@shiftit.se>
This commit is contained in:
parent
9333965b23
commit
b99476284b
@ -29,6 +29,7 @@ from .models import TeslemetryData, TeslemetryEnergyData, TeslemetryVehicleData
|
|||||||
PLATFORMS: Final = [
|
PLATFORMS: Final = [
|
||||||
Platform.BINARY_SENSOR,
|
Platform.BINARY_SENSOR,
|
||||||
Platform.CLIMATE,
|
Platform.CLIMATE,
|
||||||
|
Platform.COVER,
|
||||||
Platform.LOCK,
|
Platform.LOCK,
|
||||||
Platform.SELECT,
|
Platform.SELECT,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
|
210
homeassistant/components/teslemetry/cover.py
Normal file
210
homeassistant/components/teslemetry/cover.py
Normal file
@ -0,0 +1,210 @@
|
|||||||
|
"""Cover platform for Teslemetry integration."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from itertools import chain
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from tesla_fleet_api.const import Scope, Trunk, WindowCommand
|
||||||
|
|
||||||
|
from homeassistant.components.cover import (
|
||||||
|
CoverDeviceClass,
|
||||||
|
CoverEntity,
|
||||||
|
CoverEntityFeature,
|
||||||
|
)
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from .entity import TeslemetryVehicleEntity
|
||||||
|
from .models import TeslemetryVehicleData
|
||||||
|
|
||||||
|
OPEN = 1
|
||||||
|
CLOSED = 0
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
|
) -> None:
|
||||||
|
"""Set up the Teslemetry cover platform from a config entry."""
|
||||||
|
|
||||||
|
async_add_entities(
|
||||||
|
chain(
|
||||||
|
(
|
||||||
|
TeslemetryWindowEntity(vehicle, entry.runtime_data.scopes)
|
||||||
|
for vehicle in entry.runtime_data.vehicles
|
||||||
|
),
|
||||||
|
(
|
||||||
|
TeslemetryChargePortEntity(vehicle, entry.runtime_data.scopes)
|
||||||
|
for vehicle in entry.runtime_data.vehicles
|
||||||
|
),
|
||||||
|
(
|
||||||
|
TeslemetryFrontTrunkEntity(vehicle, entry.runtime_data.scopes)
|
||||||
|
for vehicle in entry.runtime_data.vehicles
|
||||||
|
),
|
||||||
|
(
|
||||||
|
TeslemetryRearTrunkEntity(vehicle, entry.runtime_data.scopes)
|
||||||
|
for vehicle in entry.runtime_data.vehicles
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TeslemetryWindowEntity(TeslemetryVehicleEntity, CoverEntity):
|
||||||
|
"""Cover entity for current charge."""
|
||||||
|
|
||||||
|
_attr_device_class = CoverDeviceClass.WINDOW
|
||||||
|
|
||||||
|
def __init__(self, data: TeslemetryVehicleData, scopes: list[Scope]) -> None:
|
||||||
|
"""Initialize the cover."""
|
||||||
|
super().__init__(data, "windows")
|
||||||
|
self.scoped = Scope.VEHICLE_CMDS in scopes
|
||||||
|
self._attr_supported_features = (
|
||||||
|
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
|
||||||
|
)
|
||||||
|
if not self.scoped:
|
||||||
|
self._attr_supported_features = CoverEntityFeature(0)
|
||||||
|
|
||||||
|
def _async_update_attrs(self) -> None:
|
||||||
|
"""Update the entity attributes."""
|
||||||
|
fd = self.get("vehicle_state_fd_window")
|
||||||
|
fp = self.get("vehicle_state_fp_window")
|
||||||
|
rd = self.get("vehicle_state_rd_window")
|
||||||
|
rp = self.get("vehicle_state_rp_window")
|
||||||
|
|
||||||
|
# Any open set to open
|
||||||
|
if OPEN in (fd, fp, rd, rp):
|
||||||
|
self._attr_is_closed = False
|
||||||
|
# All closed set to closed
|
||||||
|
elif CLOSED == fd == fp == rd == rp:
|
||||||
|
self._attr_is_closed = True
|
||||||
|
# Otherwise, set to unknown
|
||||||
|
else:
|
||||||
|
self._attr_is_closed = None
|
||||||
|
|
||||||
|
async def async_open_cover(self, **kwargs: Any) -> None:
|
||||||
|
"""Vent windows."""
|
||||||
|
self.raise_for_scope()
|
||||||
|
await self.wake_up_if_asleep()
|
||||||
|
await self.handle_command(self.api.window_control(command=WindowCommand.VENT))
|
||||||
|
self._attr_is_closed = False
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
async def async_close_cover(self, **kwargs: Any) -> None:
|
||||||
|
"""Close windows."""
|
||||||
|
self.raise_for_scope()
|
||||||
|
await self.wake_up_if_asleep()
|
||||||
|
await self.handle_command(self.api.window_control(command=WindowCommand.CLOSE))
|
||||||
|
self._attr_is_closed = True
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
|
||||||
|
class TeslemetryChargePortEntity(TeslemetryVehicleEntity, CoverEntity):
|
||||||
|
"""Cover entity for the charge port."""
|
||||||
|
|
||||||
|
_attr_device_class = CoverDeviceClass.DOOR
|
||||||
|
|
||||||
|
def __init__(self, vehicle: TeslemetryVehicleData, scopes: list[Scope]) -> None:
|
||||||
|
"""Initialize the cover."""
|
||||||
|
super().__init__(vehicle, "charge_state_charge_port_door_open")
|
||||||
|
self.scoped = any(
|
||||||
|
scope in scopes
|
||||||
|
for scope in (Scope.VEHICLE_CMDS, Scope.VEHICLE_CHARGING_CMDS)
|
||||||
|
)
|
||||||
|
self._attr_supported_features = (
|
||||||
|
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
|
||||||
|
)
|
||||||
|
if not self.scoped:
|
||||||
|
self._attr_supported_features = CoverEntityFeature(0)
|
||||||
|
|
||||||
|
def _async_update_attrs(self) -> None:
|
||||||
|
"""Update the entity attributes."""
|
||||||
|
self._attr_is_closed = not self._value
|
||||||
|
|
||||||
|
async def async_open_cover(self, **kwargs: Any) -> None:
|
||||||
|
"""Open charge port."""
|
||||||
|
self.raise_for_scope()
|
||||||
|
await self.wake_up_if_asleep()
|
||||||
|
await self.handle_command(self.api.charge_port_door_open())
|
||||||
|
self._attr_is_closed = False
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
async def async_close_cover(self, **kwargs: Any) -> None:
|
||||||
|
"""Close charge port."""
|
||||||
|
self.raise_for_scope()
|
||||||
|
await self.wake_up_if_asleep()
|
||||||
|
await self.handle_command(self.api.charge_port_door_close())
|
||||||
|
self._attr_is_closed = True
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
|
||||||
|
class TeslemetryFrontTrunkEntity(TeslemetryVehicleEntity, CoverEntity):
|
||||||
|
"""Cover entity for the charge port."""
|
||||||
|
|
||||||
|
_attr_device_class = CoverDeviceClass.DOOR
|
||||||
|
|
||||||
|
def __init__(self, vehicle: TeslemetryVehicleData, scopes: list[Scope]) -> None:
|
||||||
|
"""Initialize the cover."""
|
||||||
|
super().__init__(vehicle, "vehicle_state_ft")
|
||||||
|
|
||||||
|
self.scoped = Scope.VEHICLE_CMDS in scopes
|
||||||
|
self._attr_supported_features = CoverEntityFeature.OPEN
|
||||||
|
if not self.scoped:
|
||||||
|
self._attr_supported_features = CoverEntityFeature(0)
|
||||||
|
|
||||||
|
def _async_update_attrs(self) -> None:
|
||||||
|
"""Update the entity attributes."""
|
||||||
|
self._attr_is_closed = self._value == CLOSED
|
||||||
|
|
||||||
|
async def async_open_cover(self, **kwargs: Any) -> None:
|
||||||
|
"""Open front trunk."""
|
||||||
|
self.raise_for_scope()
|
||||||
|
await self.wake_up_if_asleep()
|
||||||
|
await self.handle_command(self.api.actuate_trunk(Trunk.FRONT))
|
||||||
|
self._attr_is_closed = False
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
|
||||||
|
class TeslemetryRearTrunkEntity(TeslemetryVehicleEntity, CoverEntity):
|
||||||
|
"""Cover entity for the charge port."""
|
||||||
|
|
||||||
|
_attr_device_class = CoverDeviceClass.DOOR
|
||||||
|
|
||||||
|
def __init__(self, vehicle: TeslemetryVehicleData, scopes: list[Scope]) -> None:
|
||||||
|
"""Initialize the cover."""
|
||||||
|
super().__init__(vehicle, "vehicle_state_rt")
|
||||||
|
|
||||||
|
self.scoped = Scope.VEHICLE_CMDS in scopes
|
||||||
|
self._attr_supported_features = (
|
||||||
|
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
|
||||||
|
)
|
||||||
|
if not self.scoped:
|
||||||
|
self._attr_supported_features = CoverEntityFeature(0)
|
||||||
|
|
||||||
|
def _async_update_attrs(self) -> None:
|
||||||
|
"""Update the entity attributes."""
|
||||||
|
value = self._value
|
||||||
|
if value == CLOSED:
|
||||||
|
self._attr_is_closed = True
|
||||||
|
elif value == OPEN:
|
||||||
|
self._attr_is_closed = False
|
||||||
|
else:
|
||||||
|
self._attr_is_closed = None
|
||||||
|
|
||||||
|
async def async_open_cover(self, **kwargs: Any) -> None:
|
||||||
|
"""Open rear trunk."""
|
||||||
|
if self.is_closed is not False:
|
||||||
|
self.raise_for_scope()
|
||||||
|
await self.wake_up_if_asleep()
|
||||||
|
await self.handle_command(self.api.actuate_trunk(Trunk.REAR))
|
||||||
|
self._attr_is_closed = False
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
async def async_close_cover(self, **kwargs: Any) -> None:
|
||||||
|
"""Close rear trunk."""
|
||||||
|
if self.is_closed is not True:
|
||||||
|
self.raise_for_scope()
|
||||||
|
await self.wake_up_if_asleep()
|
||||||
|
await self.handle_command(self.api.actuate_trunk(Trunk.REAR))
|
||||||
|
self._attr_is_closed = True
|
||||||
|
self.async_write_ha_state()
|
@ -126,6 +126,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"cover": {
|
||||||
|
"charge_state_charge_port_door_open": {
|
||||||
|
"default": "mdi:ev-plug-ccs2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"sensor": {
|
"sensor": {
|
||||||
"battery_power": {
|
"battery_power": {
|
||||||
"default": "mdi:home-battery"
|
"default": "mdi:home-battery"
|
||||||
|
@ -211,6 +211,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"cover": {
|
||||||
|
"charge_state_charge_port_door_open": {
|
||||||
|
"name": "Charge port door"
|
||||||
|
},
|
||||||
|
"vehicle_state_ft": {
|
||||||
|
"name": "Frunk"
|
||||||
|
},
|
||||||
|
"vehicle_state_rt": {
|
||||||
|
"name": "Trunk"
|
||||||
|
},
|
||||||
|
"windows": {
|
||||||
|
"name": "Windows"
|
||||||
|
}
|
||||||
|
},
|
||||||
"sensor": {
|
"sensor": {
|
||||||
"battery_power": {
|
"battery_power": {
|
||||||
"name": "Battery power"
|
"name": "Battery power"
|
||||||
|
@ -197,10 +197,10 @@
|
|||||||
"dashcam_state": "Recording",
|
"dashcam_state": "Recording",
|
||||||
"df": 0,
|
"df": 0,
|
||||||
"dr": 0,
|
"dr": 0,
|
||||||
"fd_window": 0,
|
"fd_window": 1,
|
||||||
"feature_bitmask": "fbdffbff,187f",
|
"feature_bitmask": "fbdffbff,187f",
|
||||||
"fp_window": 0,
|
"fp_window": 1,
|
||||||
"ft": 0,
|
"ft": 1,
|
||||||
"is_user_present": false,
|
"is_user_present": false,
|
||||||
"locked": false,
|
"locked": false,
|
||||||
"media_info": {
|
"media_info": {
|
||||||
@ -224,12 +224,12 @@
|
|||||||
"parsed_calendar_supported": true,
|
"parsed_calendar_supported": true,
|
||||||
"pf": 0,
|
"pf": 0,
|
||||||
"pr": 0,
|
"pr": 0,
|
||||||
"rd_window": 0,
|
"rd_window": 1,
|
||||||
"remote_start": false,
|
"remote_start": false,
|
||||||
"remote_start_enabled": true,
|
"remote_start_enabled": true,
|
||||||
"remote_start_supported": true,
|
"remote_start_supported": true,
|
||||||
"rp_window": 0,
|
"rp_window": 1,
|
||||||
"rt": 0,
|
"rt": 1,
|
||||||
"santa_mode": 0,
|
"santa_mode": 0,
|
||||||
"sentry_mode": false,
|
"sentry_mode": false,
|
||||||
"sentry_mode_available": true,
|
"sentry_mode_available": true,
|
||||||
|
@ -2683,7 +2683,7 @@
|
|||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_reported': <ANY>,
|
'last_reported': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': 'off',
|
'state': 'on',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_binary_sensor_refresh[binary_sensor.test_front_passenger_door-statealt]
|
# name: test_binary_sensor_refresh[binary_sensor.test_front_passenger_door-statealt]
|
||||||
@ -2711,7 +2711,7 @@
|
|||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_reported': <ANY>,
|
'last_reported': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': 'off',
|
'state': 'on',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_binary_sensor_refresh[binary_sensor.test_heat-statealt]
|
# name: test_binary_sensor_refresh[binary_sensor.test_heat-statealt]
|
||||||
@ -2928,7 +2928,7 @@
|
|||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_reported': <ANY>,
|
'last_reported': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': 'off',
|
'state': 'on',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_binary_sensor_refresh[binary_sensor.test_rear_passenger_door-statealt]
|
# name: test_binary_sensor_refresh[binary_sensor.test_rear_passenger_door-statealt]
|
||||||
@ -2956,7 +2956,7 @@
|
|||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_reported': <ANY>,
|
'last_reported': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': 'off',
|
'state': 'on',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_binary_sensor_refresh[binary_sensor.test_running-statealt]
|
# name: test_binary_sensor_refresh[binary_sensor.test_running-statealt]
|
||||||
|
577
tests/components/teslemetry/snapshots/test_cover.ambr
Normal file
577
tests/components/teslemetry/snapshots/test_cover.ambr
Normal file
@ -0,0 +1,577 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_cover[cover.test_charge_port_door-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'cover',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'cover.test_charge_port_door',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <CoverDeviceClass.DOOR: 'door'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Charge port door',
|
||||||
|
'platform': 'teslemetry',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': <CoverEntityFeature: 3>,
|
||||||
|
'translation_key': 'charge_state_charge_port_door_open',
|
||||||
|
'unique_id': 'VINVINVIN-charge_state_charge_port_door_open',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover[cover.test_charge_port_door-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'door',
|
||||||
|
'friendly_name': 'Test Charge port door',
|
||||||
|
'supported_features': <CoverEntityFeature: 3>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'cover.test_charge_port_door',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'open',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover[cover.test_frunk-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'cover',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'cover.test_frunk',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <CoverDeviceClass.DOOR: 'door'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Frunk',
|
||||||
|
'platform': 'teslemetry',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': <CoverEntityFeature: 1>,
|
||||||
|
'translation_key': 'vehicle_state_ft',
|
||||||
|
'unique_id': 'VINVINVIN-vehicle_state_ft',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover[cover.test_frunk-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'door',
|
||||||
|
'friendly_name': 'Test Frunk',
|
||||||
|
'supported_features': <CoverEntityFeature: 1>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'cover.test_frunk',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'closed',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover[cover.test_trunk-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'cover',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'cover.test_trunk',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <CoverDeviceClass.DOOR: 'door'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Trunk',
|
||||||
|
'platform': 'teslemetry',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': <CoverEntityFeature: 3>,
|
||||||
|
'translation_key': 'vehicle_state_rt',
|
||||||
|
'unique_id': 'VINVINVIN-vehicle_state_rt',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover[cover.test_trunk-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'door',
|
||||||
|
'friendly_name': 'Test Trunk',
|
||||||
|
'supported_features': <CoverEntityFeature: 3>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'cover.test_trunk',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'closed',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover[cover.test_windows-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'cover',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'cover.test_windows',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <CoverDeviceClass.WINDOW: 'window'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Windows',
|
||||||
|
'platform': 'teslemetry',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': <CoverEntityFeature: 3>,
|
||||||
|
'translation_key': 'windows',
|
||||||
|
'unique_id': 'VINVINVIN-windows',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover[cover.test_windows-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'window',
|
||||||
|
'friendly_name': 'Test Windows',
|
||||||
|
'supported_features': <CoverEntityFeature: 3>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'cover.test_windows',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'closed',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover_alt[cover.test_charge_port_door-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'cover',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'cover.test_charge_port_door',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <CoverDeviceClass.DOOR: 'door'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Charge port door',
|
||||||
|
'platform': 'teslemetry',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': <CoverEntityFeature: 3>,
|
||||||
|
'translation_key': 'charge_state_charge_port_door_open',
|
||||||
|
'unique_id': 'VINVINVIN-charge_state_charge_port_door_open',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover_alt[cover.test_charge_port_door-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'door',
|
||||||
|
'friendly_name': 'Test Charge port door',
|
||||||
|
'supported_features': <CoverEntityFeature: 3>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'cover.test_charge_port_door',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'open',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover_alt[cover.test_frunk-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'cover',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'cover.test_frunk',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <CoverDeviceClass.DOOR: 'door'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Frunk',
|
||||||
|
'platform': 'teslemetry',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': <CoverEntityFeature: 1>,
|
||||||
|
'translation_key': 'vehicle_state_ft',
|
||||||
|
'unique_id': 'VINVINVIN-vehicle_state_ft',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover_alt[cover.test_frunk-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'door',
|
||||||
|
'friendly_name': 'Test Frunk',
|
||||||
|
'supported_features': <CoverEntityFeature: 1>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'cover.test_frunk',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'open',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover_alt[cover.test_trunk-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'cover',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'cover.test_trunk',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <CoverDeviceClass.DOOR: 'door'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Trunk',
|
||||||
|
'platform': 'teslemetry',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': <CoverEntityFeature: 3>,
|
||||||
|
'translation_key': 'vehicle_state_rt',
|
||||||
|
'unique_id': 'VINVINVIN-vehicle_state_rt',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover_alt[cover.test_trunk-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'door',
|
||||||
|
'friendly_name': 'Test Trunk',
|
||||||
|
'supported_features': <CoverEntityFeature: 3>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'cover.test_trunk',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'open',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover_alt[cover.test_windows-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'cover',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'cover.test_windows',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <CoverDeviceClass.WINDOW: 'window'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Windows',
|
||||||
|
'platform': 'teslemetry',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': <CoverEntityFeature: 3>,
|
||||||
|
'translation_key': 'windows',
|
||||||
|
'unique_id': 'VINVINVIN-windows',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover_alt[cover.test_windows-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'window',
|
||||||
|
'friendly_name': 'Test Windows',
|
||||||
|
'supported_features': <CoverEntityFeature: 3>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'cover.test_windows',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'open',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover_noscope[cover.test_charge_port_door-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'cover',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'cover.test_charge_port_door',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <CoverDeviceClass.DOOR: 'door'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Charge port door',
|
||||||
|
'platform': 'teslemetry',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'charge_state_charge_port_door_open',
|
||||||
|
'unique_id': 'VINVINVIN-charge_state_charge_port_door_open',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover_noscope[cover.test_charge_port_door-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'door',
|
||||||
|
'friendly_name': 'Test Charge port door',
|
||||||
|
'supported_features': <CoverEntityFeature: 0>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'cover.test_charge_port_door',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'open',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover_noscope[cover.test_frunk-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'cover',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'cover.test_frunk',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <CoverDeviceClass.DOOR: 'door'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Frunk',
|
||||||
|
'platform': 'teslemetry',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'vehicle_state_ft',
|
||||||
|
'unique_id': 'VINVINVIN-vehicle_state_ft',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover_noscope[cover.test_frunk-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'door',
|
||||||
|
'friendly_name': 'Test Frunk',
|
||||||
|
'supported_features': <CoverEntityFeature: 0>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'cover.test_frunk',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'closed',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover_noscope[cover.test_trunk-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'cover',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'cover.test_trunk',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <CoverDeviceClass.DOOR: 'door'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Trunk',
|
||||||
|
'platform': 'teslemetry',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'vehicle_state_rt',
|
||||||
|
'unique_id': 'VINVINVIN-vehicle_state_rt',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover_noscope[cover.test_trunk-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'door',
|
||||||
|
'friendly_name': 'Test Trunk',
|
||||||
|
'supported_features': <CoverEntityFeature: 0>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'cover.test_trunk',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'closed',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover_noscope[cover.test_windows-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'cover',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'cover.test_windows',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <CoverDeviceClass.WINDOW: 'window'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Windows',
|
||||||
|
'platform': 'teslemetry',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'windows',
|
||||||
|
'unique_id': 'VINVINVIN-windows',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_cover_noscope[cover.test_windows-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'window',
|
||||||
|
'friendly_name': 'Test Windows',
|
||||||
|
'supported_features': <CoverEntityFeature: 0>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'cover.test_windows',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'closed',
|
||||||
|
})
|
||||||
|
# ---
|
188
tests/components/teslemetry/test_cover.py
Normal file
188
tests/components/teslemetry/test_cover.py
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
"""Test the Teslemetry cover platform."""
|
||||||
|
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from syrupy import SnapshotAssertion
|
||||||
|
from tesla_fleet_api.exceptions import VehicleOffline
|
||||||
|
|
||||||
|
from homeassistant.components.cover import (
|
||||||
|
DOMAIN as COVER_DOMAIN,
|
||||||
|
SERVICE_CLOSE_COVER,
|
||||||
|
SERVICE_OPEN_COVER,
|
||||||
|
)
|
||||||
|
from homeassistant.const import (
|
||||||
|
ATTR_ENTITY_ID,
|
||||||
|
STATE_CLOSED,
|
||||||
|
STATE_OPEN,
|
||||||
|
STATE_UNKNOWN,
|
||||||
|
Platform,
|
||||||
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
|
from . import assert_entities, setup_platform
|
||||||
|
from .const import COMMAND_OK, METADATA_NOSCOPE, VEHICLE_DATA_ALT
|
||||||
|
|
||||||
|
|
||||||
|
async def test_cover(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
) -> None:
|
||||||
|
"""Tests that the cover entities are correct."""
|
||||||
|
|
||||||
|
entry = await setup_platform(hass, [Platform.COVER])
|
||||||
|
assert_entities(hass, entry.entry_id, entity_registry, snapshot)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_cover_alt(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_vehicle_data,
|
||||||
|
) -> None:
|
||||||
|
"""Tests that the cover entities are correct without scopes."""
|
||||||
|
|
||||||
|
mock_vehicle_data.return_value = VEHICLE_DATA_ALT
|
||||||
|
entry = await setup_platform(hass, [Platform.COVER])
|
||||||
|
assert_entities(hass, entry.entry_id, entity_registry, snapshot)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_cover_noscope(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_metadata,
|
||||||
|
) -> None:
|
||||||
|
"""Tests that the cover entities are correct without scopes."""
|
||||||
|
|
||||||
|
mock_metadata.return_value = METADATA_NOSCOPE
|
||||||
|
entry = await setup_platform(hass, [Platform.COVER])
|
||||||
|
assert_entities(hass, entry.entry_id, entity_registry, snapshot)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_cover_offline(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_vehicle_data,
|
||||||
|
) -> None:
|
||||||
|
"""Tests that the cover entities are correct when offline."""
|
||||||
|
|
||||||
|
mock_vehicle_data.side_effect = VehicleOffline
|
||||||
|
await setup_platform(hass, [Platform.COVER])
|
||||||
|
state = hass.states.get("cover.test_windows")
|
||||||
|
assert state.state == STATE_UNKNOWN
|
||||||
|
|
||||||
|
|
||||||
|
async def test_cover_services(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
) -> None:
|
||||||
|
"""Tests that the cover entities are correct."""
|
||||||
|
|
||||||
|
await setup_platform(hass, [Platform.COVER])
|
||||||
|
|
||||||
|
# Vent Windows
|
||||||
|
entity_id = "cover.test_windows"
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.teslemetry.VehicleSpecific.window_control",
|
||||||
|
return_value=COMMAND_OK,
|
||||||
|
) as call:
|
||||||
|
await hass.services.async_call(
|
||||||
|
COVER_DOMAIN,
|
||||||
|
SERVICE_OPEN_COVER,
|
||||||
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
call.assert_called_once()
|
||||||
|
state = hass.states.get(entity_id)
|
||||||
|
assert state
|
||||||
|
assert state.state is STATE_OPEN
|
||||||
|
|
||||||
|
call.reset_mock()
|
||||||
|
await hass.services.async_call(
|
||||||
|
COVER_DOMAIN,
|
||||||
|
SERVICE_CLOSE_COVER,
|
||||||
|
{ATTR_ENTITY_ID: ["cover.test_windows"]},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
call.assert_called_once()
|
||||||
|
state = hass.states.get(entity_id)
|
||||||
|
assert state
|
||||||
|
assert state.state is STATE_CLOSED
|
||||||
|
|
||||||
|
# Charge Port Door
|
||||||
|
entity_id = "cover.test_charge_port_door"
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.teslemetry.VehicleSpecific.charge_port_door_open",
|
||||||
|
return_value=COMMAND_OK,
|
||||||
|
) as call:
|
||||||
|
await hass.services.async_call(
|
||||||
|
COVER_DOMAIN,
|
||||||
|
SERVICE_OPEN_COVER,
|
||||||
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
call.assert_called_once()
|
||||||
|
state = hass.states.get(entity_id)
|
||||||
|
assert state
|
||||||
|
assert state.state is STATE_OPEN
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.teslemetry.VehicleSpecific.charge_port_door_close",
|
||||||
|
return_value=COMMAND_OK,
|
||||||
|
) as call:
|
||||||
|
await hass.services.async_call(
|
||||||
|
COVER_DOMAIN,
|
||||||
|
SERVICE_CLOSE_COVER,
|
||||||
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
call.assert_called_once()
|
||||||
|
state = hass.states.get(entity_id)
|
||||||
|
assert state
|
||||||
|
assert state.state is STATE_CLOSED
|
||||||
|
|
||||||
|
# Frunk
|
||||||
|
entity_id = "cover.test_frunk"
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.teslemetry.VehicleSpecific.actuate_trunk",
|
||||||
|
return_value=COMMAND_OK,
|
||||||
|
) as call:
|
||||||
|
await hass.services.async_call(
|
||||||
|
COVER_DOMAIN,
|
||||||
|
SERVICE_OPEN_COVER,
|
||||||
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
call.assert_called_once()
|
||||||
|
state = hass.states.get(entity_id)
|
||||||
|
assert state
|
||||||
|
assert state.state is STATE_OPEN
|
||||||
|
|
||||||
|
# Trunk
|
||||||
|
entity_id = "cover.test_trunk"
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.teslemetry.VehicleSpecific.actuate_trunk",
|
||||||
|
return_value=COMMAND_OK,
|
||||||
|
) as call:
|
||||||
|
await hass.services.async_call(
|
||||||
|
COVER_DOMAIN,
|
||||||
|
SERVICE_OPEN_COVER,
|
||||||
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
call.assert_called_once()
|
||||||
|
state = hass.states.get(entity_id)
|
||||||
|
assert state
|
||||||
|
assert state.state is STATE_OPEN
|
||||||
|
|
||||||
|
call.reset_mock()
|
||||||
|
await hass.services.async_call(
|
||||||
|
COVER_DOMAIN,
|
||||||
|
SERVICE_CLOSE_COVER,
|
||||||
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
call.assert_called_once()
|
||||||
|
state = hass.states.get(entity_id)
|
||||||
|
assert state
|
||||||
|
assert state.state is STATE_CLOSED
|
Loading…
x
Reference in New Issue
Block a user