mirror of https://github.com/home-assistant/core
Remove mopar integration (ADR-0004) (#33066)
This commit is contained in:
parent
b6d9454b54
commit
e87fab6b5f
|
@ -432,7 +432,6 @@ omit =
|
|||
homeassistant/components/mochad/*
|
||||
homeassistant/components/modbus/*
|
||||
homeassistant/components/modem_callerid/sensor.py
|
||||
homeassistant/components/mopar/*
|
||||
homeassistant/components/mpchc/media_player.py
|
||||
homeassistant/components/mpd/media_player.py
|
||||
homeassistant/components/mqtt_room/sensor.py
|
||||
|
|
|
@ -1,140 +0,0 @@
|
|||
"""Support for Mopar vehicles."""
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
import motorparts
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.lock import DOMAIN as LOCK
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH
|
||||
from homeassistant.const import (
|
||||
CONF_PASSWORD,
|
||||
CONF_PIN,
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONF_USERNAME,
|
||||
)
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.discovery import load_platform
|
||||
from homeassistant.helpers.dispatcher import dispatcher_send
|
||||
from homeassistant.helpers.event import track_time_interval
|
||||
|
||||
DOMAIN = "mopar"
|
||||
DATA_UPDATED = f"{DOMAIN}_data_updated"
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
COOKIE_FILE = "mopar_cookies.pickle"
|
||||
SUCCESS_RESPONSE = "completed"
|
||||
|
||||
SUPPORTED_PLATFORMS = [LOCK, SENSOR, SWITCH]
|
||||
|
||||
DEFAULT_INTERVAL = timedelta(days=7)
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
DOMAIN: vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Required(CONF_PIN): cv.positive_int,
|
||||
vol.Optional(CONF_SCAN_INTERVAL, default=DEFAULT_INTERVAL): vol.All(
|
||||
cv.time_period, cv.positive_timedelta
|
||||
),
|
||||
}
|
||||
)
|
||||
},
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
SERVICE_HORN = "sound_horn"
|
||||
ATTR_VEHICLE_INDEX = "vehicle_index"
|
||||
SERVICE_HORN_SCHEMA = vol.Schema({vol.Required(ATTR_VEHICLE_INDEX): cv.positive_int})
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Set up the Mopar component."""
|
||||
conf = config[DOMAIN]
|
||||
cookie = hass.config.path(COOKIE_FILE)
|
||||
try:
|
||||
session = motorparts.get_session(
|
||||
conf[CONF_USERNAME], conf[CONF_PASSWORD], conf[CONF_PIN], cookie_path=cookie
|
||||
)
|
||||
except motorparts.MoparError:
|
||||
_LOGGER.error("Failed to login")
|
||||
return False
|
||||
|
||||
data = hass.data[DOMAIN] = MoparData(hass, session)
|
||||
data.update(now=None)
|
||||
|
||||
track_time_interval(hass, data.update, conf[CONF_SCAN_INTERVAL])
|
||||
|
||||
def handle_horn(call):
|
||||
"""Enable the horn on the Mopar vehicle."""
|
||||
data.actuate("horn", call.data[ATTR_VEHICLE_INDEX])
|
||||
|
||||
hass.services.register(
|
||||
DOMAIN, SERVICE_HORN, handle_horn, schema=SERVICE_HORN_SCHEMA
|
||||
)
|
||||
|
||||
for platform in SUPPORTED_PLATFORMS:
|
||||
load_platform(hass, platform, DOMAIN, {}, config)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
class MoparData:
|
||||
"""
|
||||
Container for Mopar vehicle data.
|
||||
|
||||
Prevents session expiry re-login race condition.
|
||||
"""
|
||||
|
||||
def __init__(self, hass, session):
|
||||
"""Initialize data."""
|
||||
self._hass = hass
|
||||
self._session = session
|
||||
self.vehicles = []
|
||||
self.vhrs = {}
|
||||
self.tow_guides = {}
|
||||
|
||||
def update(self, now, **kwargs):
|
||||
"""Update data."""
|
||||
_LOGGER.debug("Updating vehicle data")
|
||||
try:
|
||||
self.vehicles = motorparts.get_summary(self._session)["vehicles"]
|
||||
except motorparts.MoparError:
|
||||
_LOGGER.exception("Failed to get summary")
|
||||
return
|
||||
|
||||
for index, _ in enumerate(self.vehicles):
|
||||
try:
|
||||
self.vhrs[index] = motorparts.get_report(self._session, index)
|
||||
self.tow_guides[index] = motorparts.get_tow_guide(self._session, index)
|
||||
except motorparts.MoparError:
|
||||
_LOGGER.warning("Failed to update for vehicle index %s", index)
|
||||
return
|
||||
|
||||
dispatcher_send(self._hass, DATA_UPDATED)
|
||||
|
||||
@property
|
||||
def attribution(self):
|
||||
"""Get the attribution string from Mopar."""
|
||||
return motorparts.ATTRIBUTION
|
||||
|
||||
def get_vehicle_name(self, index):
|
||||
"""Get the name corresponding with this vehicle."""
|
||||
vehicle = self.vehicles[index]
|
||||
if not vehicle:
|
||||
return None
|
||||
return f"{vehicle['year']} {vehicle['make']} {vehicle['model']}"
|
||||
|
||||
def actuate(self, command, index):
|
||||
"""Run a command on the specified Mopar vehicle."""
|
||||
try:
|
||||
response = getattr(motorparts, command)(self._session, index)
|
||||
except motorparts.MoparError as error:
|
||||
_LOGGER.error(error)
|
||||
return False
|
||||
|
||||
return response == SUCCESS_RESPONSE
|
|
@ -1,52 +0,0 @@
|
|||
"""Support for the Mopar vehicle lock."""
|
||||
import logging
|
||||
|
||||
from homeassistant.components.lock import LockDevice
|
||||
from homeassistant.components.mopar import DOMAIN as MOPAR_DOMAIN
|
||||
from homeassistant.const import STATE_LOCKED, STATE_UNLOCKED
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Mopar lock platform."""
|
||||
data = hass.data[MOPAR_DOMAIN]
|
||||
add_entities(
|
||||
[MoparLock(data, index) for index, _ in enumerate(data.vehicles)], True
|
||||
)
|
||||
|
||||
|
||||
class MoparLock(LockDevice):
|
||||
"""Representation of a Mopar vehicle lock."""
|
||||
|
||||
def __init__(self, data, index):
|
||||
"""Initialize the Mopar lock."""
|
||||
self._index = index
|
||||
self._name = f"{data.get_vehicle_name(self._index)} Lock"
|
||||
self._actuate = data.actuate
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the lock."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def is_locked(self):
|
||||
"""Return true if vehicle is locked."""
|
||||
return self._state == STATE_LOCKED
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return the polling requirement for this lock."""
|
||||
return False
|
||||
|
||||
def lock(self, **kwargs):
|
||||
"""Lock the vehicle."""
|
||||
if self._actuate("lock", self._index):
|
||||
self._state = STATE_LOCKED
|
||||
|
||||
def unlock(self, **kwargs):
|
||||
"""Unlock the vehicle."""
|
||||
if self._actuate("unlock", self._index):
|
||||
self._state = STATE_UNLOCKED
|
|
@ -1,8 +0,0 @@
|
|||
{
|
||||
"domain": "mopar",
|
||||
"name": "Mopar",
|
||||
"documentation": "https://www.home-assistant.io/integrations/mopar",
|
||||
"requirements": ["motorparts==1.1.0"],
|
||||
"dependencies": [],
|
||||
"codeowners": []
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
"""Support for the Mopar vehicle sensor platform."""
|
||||
from homeassistant.components.mopar import (
|
||||
ATTR_VEHICLE_INDEX,
|
||||
DATA_UPDATED,
|
||||
DOMAIN as MOPAR_DOMAIN,
|
||||
)
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, LENGTH_KILOMETERS
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
ICON = "mdi:car"
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Mopar platform."""
|
||||
data = hass.data[MOPAR_DOMAIN]
|
||||
add_entities(
|
||||
[MoparSensor(data, index) for index, _ in enumerate(data.vehicles)], True
|
||||
)
|
||||
|
||||
|
||||
class MoparSensor(Entity):
|
||||
"""Mopar vehicle sensor."""
|
||||
|
||||
def __init__(self, data, index):
|
||||
"""Initialize the sensor."""
|
||||
self._index = index
|
||||
self._vehicle = {}
|
||||
self._vhr = {}
|
||||
self._tow_guide = {}
|
||||
self._odometer = None
|
||||
self._data = data
|
||||
self._name = self._data.get_vehicle_name(self._index)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._odometer
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
attributes = {
|
||||
ATTR_VEHICLE_INDEX: self._index,
|
||||
ATTR_ATTRIBUTION: self._data.attribution,
|
||||
}
|
||||
attributes.update(self._vehicle)
|
||||
attributes.update(self._vhr)
|
||||
attributes.update(self._tow_guide)
|
||||
return attributes
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return self.hass.config.units.length_unit
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon."""
|
||||
return ICON
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return the polling requirement for this sensor."""
|
||||
return False
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Handle entity which will be added."""
|
||||
async_dispatcher_connect(
|
||||
self.hass, DATA_UPDATED, self._schedule_immediate_update
|
||||
)
|
||||
|
||||
def update(self):
|
||||
"""Update device state."""
|
||||
self._vehicle = self._data.vehicles[self._index]
|
||||
self._vhr = self._data.vhrs.get(self._index, {})
|
||||
self._tow_guide = self._data.tow_guides.get(self._index, {})
|
||||
if "odometer" in self._vhr:
|
||||
odo = float(self._vhr["odometer"])
|
||||
self._odometer = int(self.hass.config.units.length(odo, LENGTH_KILOMETERS))
|
||||
|
||||
@callback
|
||||
def _schedule_immediate_update(self):
|
||||
self.async_schedule_update_ha_state(True)
|
|
@ -1,6 +0,0 @@
|
|||
sound_horn:
|
||||
description: Trigger the vehicle's horn
|
||||
fields:
|
||||
vehicle_index:
|
||||
description: The index of the vehicle to trigger. This is exposed in the sensor's device attributes.
|
||||
example: 1
|
|
@ -1,52 +0,0 @@
|
|||
"""Support for the Mopar vehicle switch."""
|
||||
import logging
|
||||
|
||||
from homeassistant.components.mopar import DOMAIN as MOPAR_DOMAIN
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
from homeassistant.const import STATE_OFF, STATE_ON
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Mopar Switch platform."""
|
||||
data = hass.data[MOPAR_DOMAIN]
|
||||
add_entities(
|
||||
[MoparSwitch(data, index) for index, _ in enumerate(data.vehicles)], True
|
||||
)
|
||||
|
||||
|
||||
class MoparSwitch(SwitchDevice):
|
||||
"""Representation of a Mopar switch."""
|
||||
|
||||
def __init__(self, data, index):
|
||||
"""Initialize the Switch."""
|
||||
self._index = index
|
||||
self._name = f"{data.get_vehicle_name(self._index)} Switch"
|
||||
self._actuate = data.actuate
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the switch."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return True if the entity is on."""
|
||||
return self._state == STATE_ON
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return the polling requirement for this switch."""
|
||||
return False
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn on the Mopar Vehicle."""
|
||||
if self._actuate("engine_on", self._index):
|
||||
self._state = STATE_ON
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn off the Mopar Vehicle."""
|
||||
if self._actuate("engine_off", self._index):
|
||||
self._state = STATE_OFF
|
|
@ -882,9 +882,6 @@ minio==4.0.9
|
|||
# homeassistant.components.mitemp_bt
|
||||
mitemp_bt==0.0.3
|
||||
|
||||
# homeassistant.components.mopar
|
||||
motorparts==1.1.0
|
||||
|
||||
# homeassistant.components.tts
|
||||
mutagen==1.43.0
|
||||
|
||||
|
|
Loading…
Reference in New Issue