Remove deprecated services from Mazda integration (#73403)
This commit is contained in:
parent
23e17c5b47
commit
f85409b2ea
4 changed files with 51 additions and 128 deletions
|
@ -33,7 +33,7 @@ from homeassistant.helpers.update_coordinator import (
|
|||
UpdateFailed,
|
||||
)
|
||||
|
||||
from .const import DATA_CLIENT, DATA_COORDINATOR, DATA_VEHICLES, DOMAIN, SERVICES
|
||||
from .const import DATA_CLIENT, DATA_COORDINATOR, DATA_VEHICLES, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -109,34 +109,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
if vehicle_id == 0 or api_client is None:
|
||||
raise HomeAssistantError("Vehicle ID not found")
|
||||
|
||||
if service_call.service in (
|
||||
"start_engine",
|
||||
"stop_engine",
|
||||
"turn_on_hazard_lights",
|
||||
"turn_off_hazard_lights",
|
||||
):
|
||||
_LOGGER.warning(
|
||||
"The mazda.%s service is deprecated and has been replaced by a button entity; "
|
||||
"Please use the button entity instead",
|
||||
service_call.service,
|
||||
)
|
||||
|
||||
if service_call.service in ("start_charging", "stop_charging"):
|
||||
_LOGGER.warning(
|
||||
"The mazda.%s service is deprecated and has been replaced by a switch entity; "
|
||||
"Please use the charging switch entity instead",
|
||||
service_call.service,
|
||||
)
|
||||
|
||||
api_method = getattr(api_client, service_call.service)
|
||||
try:
|
||||
if service_call.service == "send_poi":
|
||||
latitude = service_call.data["latitude"]
|
||||
longitude = service_call.data["longitude"]
|
||||
poi_name = service_call.data["poi_name"]
|
||||
await api_method(vehicle_id, latitude, longitude, poi_name)
|
||||
else:
|
||||
await api_method(vehicle_id)
|
||||
latitude = service_call.data["latitude"]
|
||||
longitude = service_call.data["longitude"]
|
||||
poi_name = service_call.data["poi_name"]
|
||||
await api_method(vehicle_id, latitude, longitude, poi_name)
|
||||
except Exception as ex:
|
||||
raise HomeAssistantError(ex) from ex
|
||||
|
||||
|
@ -157,12 +135,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
return device_id
|
||||
|
||||
service_schema = vol.Schema(
|
||||
{vol.Required("device_id"): vol.All(cv.string, validate_mazda_device_id)}
|
||||
)
|
||||
|
||||
service_schema_send_poi = service_schema.extend(
|
||||
service_schema_send_poi = vol.Schema(
|
||||
{
|
||||
vol.Required("device_id"): vol.All(cv.string, validate_mazda_device_id),
|
||||
vol.Required("latitude"): cv.latitude,
|
||||
vol.Required("longitude"): cv.longitude,
|
||||
vol.Required("poi_name"): cv.string,
|
||||
|
@ -220,13 +195,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
|
||||
# Register services
|
||||
for service in SERVICES:
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
service,
|
||||
async_handle_service_call,
|
||||
schema=service_schema_send_poi if service == "send_poi" else service_schema,
|
||||
)
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
"send_poi",
|
||||
async_handle_service_call,
|
||||
schema=service_schema_send_poi,
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
@ -237,8 +211,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
# Only remove services if it is the last config entry
|
||||
if len(hass.data[DOMAIN]) == 1:
|
||||
for service in SERVICES:
|
||||
hass.services.async_remove(DOMAIN, service)
|
||||
hass.services.async_remove(DOMAIN, "send_poi")
|
||||
|
||||
if unload_ok:
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
|
|
@ -7,13 +7,3 @@ DATA_COORDINATOR = "coordinator"
|
|||
DATA_VEHICLES = "vehicles"
|
||||
|
||||
MAZDA_REGIONS = {"MNAO": "North America", "MME": "Europe", "MJO": "Japan"}
|
||||
|
||||
SERVICES = [
|
||||
"send_poi",
|
||||
"start_charging",
|
||||
"start_engine",
|
||||
"stop_charging",
|
||||
"stop_engine",
|
||||
"turn_off_hazard_lights",
|
||||
"turn_on_hazard_lights",
|
||||
]
|
||||
|
|
|
@ -1,47 +1,3 @@
|
|||
start_engine:
|
||||
name: Start engine
|
||||
description: Start the vehicle engine.
|
||||
fields:
|
||||
device_id:
|
||||
name: Vehicle
|
||||
description: The vehicle to start
|
||||
required: true
|
||||
selector:
|
||||
device:
|
||||
integration: mazda
|
||||
stop_engine:
|
||||
name: Stop engine
|
||||
description: Stop the vehicle engine.
|
||||
fields:
|
||||
device_id:
|
||||
name: Vehicle
|
||||
description: The vehicle to stop
|
||||
required: true
|
||||
selector:
|
||||
device:
|
||||
integration: mazda
|
||||
turn_on_hazard_lights:
|
||||
name: Turn on hazard lights
|
||||
description: Turn on the vehicle hazard lights. The lights will flash briefly and then turn off.
|
||||
fields:
|
||||
device_id:
|
||||
name: Vehicle
|
||||
description: The vehicle to turn hazard lights on
|
||||
required: true
|
||||
selector:
|
||||
device:
|
||||
integration: mazda
|
||||
turn_off_hazard_lights:
|
||||
name: Turn off hazard lights
|
||||
description: Turn off the vehicle hazard lights if they have been manually turned on from inside the vehicle.
|
||||
fields:
|
||||
device_id:
|
||||
name: Vehicle
|
||||
description: The vehicle to turn hazard lights off
|
||||
required: true
|
||||
selector:
|
||||
device:
|
||||
integration: mazda
|
||||
send_poi:
|
||||
name: Send POI
|
||||
description: Send a GPS location to the vehicle's navigation system as a POI (Point of Interest). Requires a navigation SD card installed in the vehicle.
|
||||
|
@ -82,25 +38,3 @@ send_poi:
|
|||
required: true
|
||||
selector:
|
||||
text:
|
||||
start_charging:
|
||||
name: Start charging
|
||||
description: Start charging the vehicle. For electric vehicles only.
|
||||
fields:
|
||||
device_id:
|
||||
name: Vehicle
|
||||
description: The vehicle to start charging
|
||||
required: true
|
||||
selector:
|
||||
device:
|
||||
integration: mazda
|
||||
stop_charging:
|
||||
name: Stop charging
|
||||
description: Stop charging the vehicle. For electric vehicles only.
|
||||
fields:
|
||||
device_id:
|
||||
name: Vehicle
|
||||
description: The vehicle to stop charging
|
||||
required: true
|
||||
selector:
|
||||
device:
|
||||
integration: mazda
|
||||
|
|
|
@ -203,12 +203,6 @@ async def test_device_no_nickname(hass):
|
|||
@pytest.mark.parametrize(
|
||||
"service, service_data, expected_args",
|
||||
[
|
||||
("start_charging", {}, [12345]),
|
||||
("start_engine", {}, [12345]),
|
||||
("stop_charging", {}, [12345]),
|
||||
("stop_engine", {}, [12345]),
|
||||
("turn_off_hazard_lights", {}, [12345]),
|
||||
("turn_on_hazard_lights", {}, [12345]),
|
||||
(
|
||||
"send_poi",
|
||||
{"latitude": 1.2345, "longitude": 2.3456, "poi_name": "Work"},
|
||||
|
@ -241,7 +235,15 @@ async def test_service_invalid_device_id(hass):
|
|||
|
||||
with pytest.raises(vol.error.MultipleInvalid) as err:
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "start_engine", {"device_id": "invalid"}, blocking=True
|
||||
DOMAIN,
|
||||
"send_poi",
|
||||
{
|
||||
"device_id": "invalid",
|
||||
"latitude": 1.2345,
|
||||
"longitude": 6.7890,
|
||||
"poi_name": "poi_name",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -262,7 +264,15 @@ async def test_service_device_id_not_mazda_vehicle(hass):
|
|||
|
||||
with pytest.raises(vol.error.MultipleInvalid) as err:
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "start_engine", {"device_id": other_device.id}, blocking=True
|
||||
DOMAIN,
|
||||
"send_poi",
|
||||
{
|
||||
"device_id": other_device.id,
|
||||
"latitude": 1.2345,
|
||||
"longitude": 6.7890,
|
||||
"poi_name": "poi_name",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -287,7 +297,15 @@ async def test_service_vehicle_id_not_found(hass):
|
|||
|
||||
with pytest.raises(HomeAssistantError) as err:
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "start_engine", {"device_id": device_id}, blocking=True
|
||||
DOMAIN,
|
||||
"send_poi",
|
||||
{
|
||||
"device_id": device_id,
|
||||
"latitude": 1.2345,
|
||||
"longitude": 6.7890,
|
||||
"poi_name": "poi_name",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -324,11 +342,19 @@ async def test_service_mazda_api_error(hass):
|
|||
device_id = reg_device.id
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.mazda.MazdaAPI.start_engine",
|
||||
"homeassistant.components.mazda.MazdaAPI.send_poi",
|
||||
side_effect=MazdaException("Test error"),
|
||||
), pytest.raises(HomeAssistantError) as err:
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "start_engine", {"device_id": device_id}, blocking=True
|
||||
DOMAIN,
|
||||
"send_poi",
|
||||
{
|
||||
"device_id": device_id,
|
||||
"latitude": 1.2345,
|
||||
"longitude": 6.7890,
|
||||
"poi_name": "poi_name",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue