Remove deprecated speed limit lock entity from tessie (#128043)
Remove deprecated speedlimit lock entity from tessiepull/128114/head
parent
0fcbfa996f
commit
9f7eb36a1f
|
@ -4,21 +4,11 @@ from __future__ import annotations
|
|||
|
||||
from typing import Any
|
||||
|
||||
from tessie_api import (
|
||||
disable_speed_limit,
|
||||
enable_speed_limit,
|
||||
lock,
|
||||
open_unlock_charge_port,
|
||||
unlock,
|
||||
)
|
||||
from tessie_api import lock, open_unlock_charge_port, unlock
|
||||
|
||||
from homeassistant.components.automation import automations_with_entity
|
||||
from homeassistant.components.lock import ATTR_CODE, LockEntity
|
||||
from homeassistant.components.script import scripts_with_entity
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.components.lock import LockEntity
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.helpers import entity_registry as er, issue_registry as ir
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import TessieConfigEntry
|
||||
|
@ -37,46 +27,11 @@ async def async_setup_entry(
|
|||
"""Set up the Tessie sensor platform from a config entry."""
|
||||
data = entry.runtime_data
|
||||
|
||||
entities: list[TessieEntity] = [
|
||||
async_add_entities(
|
||||
klass(vehicle)
|
||||
for klass in (TessieLockEntity, TessieCableLockEntity)
|
||||
for vehicle in data.vehicles
|
||||
]
|
||||
|
||||
ent_reg = er.async_get(hass)
|
||||
|
||||
for vehicle in data.vehicles:
|
||||
entity_id = ent_reg.async_get_entity_id(
|
||||
Platform.LOCK,
|
||||
DOMAIN,
|
||||
f"{vehicle.vin}-vehicle_state_speed_limit_mode_active",
|
||||
)
|
||||
if entity_id:
|
||||
entity_entry = ent_reg.async_get(entity_id)
|
||||
assert entity_entry
|
||||
if entity_entry.disabled:
|
||||
ent_reg.async_remove(entity_id)
|
||||
else:
|
||||
entities.append(TessieSpeedLimitEntity(vehicle))
|
||||
|
||||
entity_automations = automations_with_entity(hass, entity_id)
|
||||
entity_scripts = scripts_with_entity(hass, entity_id)
|
||||
for item in entity_automations + entity_scripts:
|
||||
ir.async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
f"deprecated_speed_limit_{entity_id}_{item}",
|
||||
breaks_in_ha_version="2024.11.0",
|
||||
is_fixable=True,
|
||||
is_persistent=False,
|
||||
severity=ir.IssueSeverity.WARNING,
|
||||
translation_key="deprecated_speed_limit_entity",
|
||||
translation_placeholders={
|
||||
"entity": entity_id,
|
||||
"info": item,
|
||||
},
|
||||
)
|
||||
async_add_entities(entities)
|
||||
)
|
||||
|
||||
|
||||
class TessieLockEntity(TessieEntity, LockEntity):
|
||||
|
@ -105,58 +60,6 @@ class TessieLockEntity(TessieEntity, LockEntity):
|
|||
self.set((self.key, False))
|
||||
|
||||
|
||||
class TessieSpeedLimitEntity(TessieEntity, LockEntity):
|
||||
"""Speed Limit with PIN entity for Tessie."""
|
||||
|
||||
_attr_code_format = r"^\d\d\d\d$"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
vehicle: TessieVehicleData,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(vehicle, "vehicle_state_speed_limit_mode_active")
|
||||
|
||||
@property
|
||||
def is_locked(self) -> bool | None:
|
||||
"""Return the state of the Lock."""
|
||||
return self._value
|
||||
|
||||
async def async_lock(self, **kwargs: Any) -> None:
|
||||
"""Enable speed limit with pin."""
|
||||
ir.async_create_issue(
|
||||
self.coordinator.hass,
|
||||
DOMAIN,
|
||||
"deprecated_speed_limit_locked",
|
||||
breaks_in_ha_version="2024.11.0",
|
||||
is_fixable=True,
|
||||
is_persistent=False,
|
||||
severity=ir.IssueSeverity.WARNING,
|
||||
translation_key="deprecated_speed_limit_locked",
|
||||
)
|
||||
code: str | None = kwargs.get(ATTR_CODE)
|
||||
if code:
|
||||
await self.run(enable_speed_limit, pin=code)
|
||||
self.set((self.key, True))
|
||||
|
||||
async def async_unlock(self, **kwargs: Any) -> None:
|
||||
"""Disable speed limit with pin."""
|
||||
ir.async_create_issue(
|
||||
self.coordinator.hass,
|
||||
DOMAIN,
|
||||
"deprecated_speed_limit_unlocked",
|
||||
breaks_in_ha_version="2024.11.0",
|
||||
is_fixable=True,
|
||||
is_persistent=False,
|
||||
severity=ir.IssueSeverity.WARNING,
|
||||
translation_key="deprecated_speed_limit_unlocked",
|
||||
)
|
||||
code: str | None = kwargs.get(ATTR_CODE)
|
||||
if code:
|
||||
await self.run(disable_speed_limit, pin=code)
|
||||
self.set((self.key, False))
|
||||
|
||||
|
||||
class TessieCableLockEntity(TessieEntity, LockEntity):
|
||||
"""Cable Lock entity for Tessie."""
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import pytest
|
|||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.lock import (
|
||||
ATTR_CODE,
|
||||
DOMAIN as LOCK_DOMAIN,
|
||||
SERVICE_LOCK,
|
||||
SERVICE_UNLOCK,
|
||||
|
@ -15,9 +14,9 @@ from homeassistant.components.lock import (
|
|||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.helpers import entity_registry as er, issue_registry as ir
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .common import DOMAIN, assert_entities, setup_platform
|
||||
from .common import assert_entities, setup_platform
|
||||
|
||||
|
||||
async def test_locks(
|
||||
|
@ -25,17 +24,6 @@ async def test_locks(
|
|||
) -> None:
|
||||
"""Tests that the lock entity is correct."""
|
||||
|
||||
# Create the deprecated speed limit lock entity
|
||||
entity_registry.async_get_or_create(
|
||||
LOCK_DOMAIN,
|
||||
DOMAIN,
|
||||
"VINVINVIN-vehicle_state_speed_limit_mode_active",
|
||||
original_name="Charge cable lock",
|
||||
has_entity_name=True,
|
||||
translation_key="vehicle_state_speed_limit_mode_active",
|
||||
disabled_by=er.RegistryEntryDisabler.INTEGRATION,
|
||||
)
|
||||
|
||||
entry = await setup_platform(hass, [Platform.LOCK])
|
||||
|
||||
assert_entities(hass, entry.entry_id, entity_registry, snapshot)
|
||||
|
@ -83,65 +71,3 @@ async def test_locks(
|
|||
)
|
||||
assert hass.states.get(entity_id).state == LockState.UNLOCKED
|
||||
mock_run.assert_called_once()
|
||||
|
||||
|
||||
async def test_speed_limit_lock(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
) -> None:
|
||||
"""Tests that the deprecated speed limit lock entity is correct."""
|
||||
# Create the deprecated speed limit lock entity
|
||||
entity = entity_registry.async_get_or_create(
|
||||
LOCK_DOMAIN,
|
||||
DOMAIN,
|
||||
"VINVINVIN-vehicle_state_speed_limit_mode_active",
|
||||
original_name="Charge cable lock",
|
||||
has_entity_name=True,
|
||||
translation_key="vehicle_state_speed_limit_mode_active",
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.tessie.lock.automations_with_entity",
|
||||
return_value=["item"],
|
||||
):
|
||||
await setup_platform(hass, [Platform.LOCK])
|
||||
assert issue_registry.async_get_issue(
|
||||
DOMAIN, f"deprecated_speed_limit_{entity.entity_id}_item"
|
||||
)
|
||||
|
||||
# Test lock set value functions
|
||||
with patch(
|
||||
"homeassistant.components.tessie.lock.enable_speed_limit"
|
||||
) as mock_enable_speed_limit:
|
||||
await hass.services.async_call(
|
||||
LOCK_DOMAIN,
|
||||
SERVICE_LOCK,
|
||||
{ATTR_ENTITY_ID: [entity.entity_id], ATTR_CODE: "1234"},
|
||||
blocking=True,
|
||||
)
|
||||
assert hass.states.get(entity.entity_id).state == LockState.LOCKED
|
||||
mock_enable_speed_limit.assert_called_once()
|
||||
# Assert issue has been raised in the issue register
|
||||
assert issue_registry.async_get_issue(DOMAIN, "deprecated_speed_limit_locked")
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.tessie.lock.disable_speed_limit"
|
||||
) as mock_disable_speed_limit:
|
||||
await hass.services.async_call(
|
||||
LOCK_DOMAIN,
|
||||
SERVICE_UNLOCK,
|
||||
{ATTR_ENTITY_ID: [entity.entity_id], ATTR_CODE: "1234"},
|
||||
blocking=True,
|
||||
)
|
||||
assert hass.states.get(entity.entity_id).state == LockState.UNLOCKED
|
||||
mock_disable_speed_limit.assert_called_once()
|
||||
assert issue_registry.async_get_issue(DOMAIN, "deprecated_speed_limit_unlocked")
|
||||
|
||||
with pytest.raises(ServiceValidationError):
|
||||
await hass.services.async_call(
|
||||
LOCK_DOMAIN,
|
||||
SERVICE_UNLOCK,
|
||||
{ATTR_ENTITY_ID: [entity.entity_id], ATTR_CODE: "abc"},
|
||||
blocking=True,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue