mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Remove MercedesME component (#13538)
This commit is contained in:
parent
2518587534
commit
3b4faa74a0
@ -159,10 +159,7 @@ omit =
|
|||||||
|
|
||||||
homeassistant/components/maxcube.py
|
homeassistant/components/maxcube.py
|
||||||
homeassistant/components/*/maxcube.py
|
homeassistant/components/*/maxcube.py
|
||||||
|
|
||||||
homeassistant/components/mercedesme.py
|
|
||||||
homeassistant/components/*/mercedesme.py
|
|
||||||
|
|
||||||
homeassistant/components/mochad.py
|
homeassistant/components/mochad.py
|
||||||
homeassistant/components/*/mochad.py
|
homeassistant/components/*/mochad.py
|
||||||
|
|
||||||
|
@ -1,97 +0,0 @@
|
|||||||
"""
|
|
||||||
Support for Mercedes cars with Mercedes ME.
|
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
|
||||||
https://home-assistant.io/components/binary_sensor.mercedesme/
|
|
||||||
"""
|
|
||||||
import logging
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (BinarySensorDevice)
|
|
||||||
from homeassistant.components.mercedesme import (
|
|
||||||
DATA_MME, FEATURE_NOT_AVAILABLE, MercedesMeEntity, BINARY_SENSORS)
|
|
||||||
|
|
||||||
DEPENDENCIES = ['mercedesme']
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
|
||||||
"""Setup the sensor platform."""
|
|
||||||
data = hass.data[DATA_MME].data
|
|
||||||
|
|
||||||
if not data.cars:
|
|
||||||
_LOGGER.error("No cars found. Check component log.")
|
|
||||||
return
|
|
||||||
|
|
||||||
devices = []
|
|
||||||
for car in data.cars:
|
|
||||||
for key, value in sorted(BINARY_SENSORS.items()):
|
|
||||||
if car['availabilities'].get(key, 'INVALID') == 'VALID':
|
|
||||||
devices.append(MercedesMEBinarySensor(
|
|
||||||
data, key, value[0], car["vin"], None))
|
|
||||||
else:
|
|
||||||
_LOGGER.warning(FEATURE_NOT_AVAILABLE, key, car["license"])
|
|
||||||
|
|
||||||
add_devices(devices, True)
|
|
||||||
|
|
||||||
|
|
||||||
class MercedesMEBinarySensor(MercedesMeEntity, BinarySensorDevice):
|
|
||||||
"""Representation of a Sensor."""
|
|
||||||
|
|
||||||
@property
|
|
||||||
def is_on(self):
|
|
||||||
"""Return the state of the binary sensor."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_state_attributes(self):
|
|
||||||
"""Return the state attributes."""
|
|
||||||
if self._internal_name == "windowsClosed":
|
|
||||||
return {
|
|
||||||
"window_front_left": self._car["windowStatusFrontLeft"],
|
|
||||||
"window_front_right": self._car["windowStatusFrontRight"],
|
|
||||||
"window_rear_left": self._car["windowStatusRearLeft"],
|
|
||||||
"window_rear_right": self._car["windowStatusRearRight"],
|
|
||||||
"original_value": self._car[self._internal_name],
|
|
||||||
"last_update": datetime.datetime.fromtimestamp(
|
|
||||||
self._car["lastUpdate"]).strftime('%Y-%m-%d %H:%M:%S'),
|
|
||||||
"car": self._car["license"]
|
|
||||||
}
|
|
||||||
elif self._internal_name == "tireWarningLight":
|
|
||||||
return {
|
|
||||||
"front_right_tire_pressure_kpa":
|
|
||||||
self._car["frontRightTirePressureKpa"],
|
|
||||||
"front_left_tire_pressure_kpa":
|
|
||||||
self._car["frontLeftTirePressureKpa"],
|
|
||||||
"rear_right_tire_pressure_kpa":
|
|
||||||
self._car["rearRightTirePressureKpa"],
|
|
||||||
"rear_left_tire_pressure_kpa":
|
|
||||||
self._car["rearLeftTirePressureKpa"],
|
|
||||||
"original_value": self._car[self._internal_name],
|
|
||||||
"last_update": datetime.datetime.fromtimestamp(
|
|
||||||
self._car["lastUpdate"]
|
|
||||||
).strftime('%Y-%m-%d %H:%M:%S'),
|
|
||||||
"car": self._car["license"],
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
"original_value": self._car[self._internal_name],
|
|
||||||
"last_update": datetime.datetime.fromtimestamp(
|
|
||||||
self._car["lastUpdate"]).strftime('%Y-%m-%d %H:%M:%S'),
|
|
||||||
"car": self._car["license"]
|
|
||||||
}
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
"""Fetch new state data for the sensor."""
|
|
||||||
self._car = next(
|
|
||||||
car for car in self._data.cars if car["vin"] == self._vin)
|
|
||||||
|
|
||||||
if self._internal_name == "windowsClosed":
|
|
||||||
self._state = bool(self._car[self._internal_name] == "CLOSED")
|
|
||||||
elif self._internal_name == "tireWarningLight":
|
|
||||||
self._state = bool(self._car[self._internal_name] != "INACTIVE")
|
|
||||||
else:
|
|
||||||
self._state = self._car[self._internal_name] is True
|
|
||||||
|
|
||||||
_LOGGER.debug("Updated %s Value: %s IsOn: %s",
|
|
||||||
self._internal_name, self._state, self.is_on)
|
|
@ -1,74 +0,0 @@
|
|||||||
"""
|
|
||||||
Support for Mercedes cars with Mercedes ME.
|
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
|
||||||
https://home-assistant.io/components/device_tracker.mercedesme/
|
|
||||||
"""
|
|
||||||
import logging
|
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
from homeassistant.components.mercedesme import DATA_MME
|
|
||||||
from homeassistant.helpers.event import track_time_interval
|
|
||||||
from homeassistant.util import Throttle
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
DEPENDENCIES = ['mercedesme']
|
|
||||||
|
|
||||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=30)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_scanner(hass, config, see, discovery_info=None):
|
|
||||||
"""Set up the Mercedes ME tracker."""
|
|
||||||
if discovery_info is None:
|
|
||||||
return False
|
|
||||||
|
|
||||||
data = hass.data[DATA_MME].data
|
|
||||||
|
|
||||||
if not data.cars:
|
|
||||||
return False
|
|
||||||
|
|
||||||
MercedesMEDeviceTracker(hass, config, see, data)
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class MercedesMEDeviceTracker(object):
|
|
||||||
"""A class representing a Mercedes ME device tracker."""
|
|
||||||
|
|
||||||
def __init__(self, hass, config, see, data):
|
|
||||||
"""Initialize the Mercedes ME device tracker."""
|
|
||||||
self.see = see
|
|
||||||
self.data = data
|
|
||||||
self.update_info()
|
|
||||||
|
|
||||||
track_time_interval(
|
|
||||||
hass, self.update_info, MIN_TIME_BETWEEN_SCANS)
|
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_SCANS)
|
|
||||||
def update_info(self, now=None):
|
|
||||||
"""Update the device info."""
|
|
||||||
for device in self.data.cars:
|
|
||||||
if not device['services'].get('VEHICLE_FINDER', False):
|
|
||||||
continue
|
|
||||||
|
|
||||||
location = self.data.get_location(device["vin"])
|
|
||||||
if location is None:
|
|
||||||
continue
|
|
||||||
|
|
||||||
dev_id = device["vin"]
|
|
||||||
name = device["license"]
|
|
||||||
|
|
||||||
lat = location['positionLat']['value']
|
|
||||||
lon = location['positionLong']['value']
|
|
||||||
attrs = {
|
|
||||||
'trackr_id': dev_id,
|
|
||||||
'id': dev_id,
|
|
||||||
'name': name
|
|
||||||
}
|
|
||||||
self.see(
|
|
||||||
dev_id=dev_id, host_name=name,
|
|
||||||
gps=(lat, lon), attributes=attrs
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
|
@ -1,156 +0,0 @@
|
|||||||
"""
|
|
||||||
Support for MercedesME System.
|
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
|
||||||
https://home-assistant.io/components/mercedesme/
|
|
||||||
"""
|
|
||||||
import asyncio
|
|
||||||
import logging
|
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
import voluptuous as vol
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
|
|
||||||
from homeassistant.const import (
|
|
||||||
CONF_USERNAME, CONF_PASSWORD, CONF_SCAN_INTERVAL, LENGTH_KILOMETERS)
|
|
||||||
from homeassistant.helpers import discovery
|
|
||||||
from homeassistant.helpers.dispatcher import (
|
|
||||||
async_dispatcher_connect, dispatcher_send)
|
|
||||||
from homeassistant.helpers.entity import Entity
|
|
||||||
from homeassistant.helpers.event import track_time_interval
|
|
||||||
|
|
||||||
REQUIREMENTS = ['mercedesmejsonpy==0.1.2']
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
BINARY_SENSORS = {
|
|
||||||
'doorsClosed': ['Doors closed'],
|
|
||||||
'windowsClosed': ['Windows closed'],
|
|
||||||
'locked': ['Doors locked'],
|
|
||||||
'tireWarningLight': ['Tire Warning']
|
|
||||||
}
|
|
||||||
|
|
||||||
SENSORS = {
|
|
||||||
'fuelLevelPercent': ['Fuel Level', '%'],
|
|
||||||
'fuelRangeKm': ['Fuel Range', LENGTH_KILOMETERS],
|
|
||||||
'latestTrip': ['Latest Trip', None],
|
|
||||||
'odometerKm': ['Odometer', LENGTH_KILOMETERS],
|
|
||||||
'serviceIntervalDays': ['Next Service', 'days']
|
|
||||||
}
|
|
||||||
|
|
||||||
DATA_MME = 'mercedesme'
|
|
||||||
DOMAIN = 'mercedesme'
|
|
||||||
|
|
||||||
FEATURE_NOT_AVAILABLE = "The feature %s is not available for your car %s"
|
|
||||||
|
|
||||||
NOTIFICATION_ID = 'mercedesme_integration_notification'
|
|
||||||
NOTIFICATION_TITLE = 'Mercedes me integration setup'
|
|
||||||
|
|
||||||
SIGNAL_UPDATE_MERCEDESME = "mercedesme_update"
|
|
||||||
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema({
|
|
||||||
DOMAIN: vol.Schema({
|
|
||||||
vol.Required(CONF_USERNAME): cv.string,
|
|
||||||
vol.Required(CONF_PASSWORD): cv.string,
|
|
||||||
vol.Optional(CONF_SCAN_INTERVAL, default=30):
|
|
||||||
vol.All(cv.positive_int, vol.Clamp(min=10))
|
|
||||||
})
|
|
||||||
}, extra=vol.ALLOW_EXTRA)
|
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
|
||||||
"""Set up MercedesMe System."""
|
|
||||||
from mercedesmejsonpy.controller import Controller
|
|
||||||
from mercedesmejsonpy import Exceptions
|
|
||||||
|
|
||||||
conf = config[DOMAIN]
|
|
||||||
username = conf.get(CONF_USERNAME)
|
|
||||||
password = conf.get(CONF_PASSWORD)
|
|
||||||
scan_interval = conf.get(CONF_SCAN_INTERVAL)
|
|
||||||
|
|
||||||
try:
|
|
||||||
mercedesme_api = Controller(username, password, scan_interval)
|
|
||||||
if not mercedesme_api.is_valid_session:
|
|
||||||
raise Exceptions.MercedesMeException(500)
|
|
||||||
hass.data[DATA_MME] = MercedesMeHub(mercedesme_api)
|
|
||||||
except Exceptions.MercedesMeException as ex:
|
|
||||||
if ex.code == 401:
|
|
||||||
hass.components.persistent_notification.create(
|
|
||||||
"Error:<br />Please check username and password."
|
|
||||||
"You will need to restart Home Assistant after fixing.",
|
|
||||||
title=NOTIFICATION_TITLE,
|
|
||||||
notification_id=NOTIFICATION_ID)
|
|
||||||
else:
|
|
||||||
hass.components.persistent_notification.create(
|
|
||||||
"Error:<br />Can't communicate with Mercedes me API.<br />"
|
|
||||||
"Error code: {} Reason: {}"
|
|
||||||
"You will need to restart Home Assistant after fixing."
|
|
||||||
"".format(ex.code, ex.message),
|
|
||||||
title=NOTIFICATION_TITLE,
|
|
||||||
notification_id=NOTIFICATION_ID)
|
|
||||||
|
|
||||||
_LOGGER.error("Unable to communicate with Mercedes me API: %s",
|
|
||||||
ex.message)
|
|
||||||
return False
|
|
||||||
|
|
||||||
discovery.load_platform(hass, 'sensor', DOMAIN, {}, config)
|
|
||||||
discovery.load_platform(hass, 'device_tracker', DOMAIN, {}, config)
|
|
||||||
discovery.load_platform(hass, 'binary_sensor', DOMAIN, {}, config)
|
|
||||||
|
|
||||||
def hub_refresh(event_time):
|
|
||||||
"""Call Mercedes me API to refresh information."""
|
|
||||||
_LOGGER.info("Updating Mercedes me component.")
|
|
||||||
hass.data[DATA_MME].data.update()
|
|
||||||
dispatcher_send(hass, SIGNAL_UPDATE_MERCEDESME)
|
|
||||||
|
|
||||||
track_time_interval(
|
|
||||||
hass,
|
|
||||||
hub_refresh,
|
|
||||||
timedelta(seconds=scan_interval))
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class MercedesMeHub(object):
|
|
||||||
"""Representation of a base MercedesMe device."""
|
|
||||||
|
|
||||||
def __init__(self, data):
|
|
||||||
"""Initialize the entity."""
|
|
||||||
self.data = data
|
|
||||||
|
|
||||||
|
|
||||||
class MercedesMeEntity(Entity):
|
|
||||||
"""Entity class for MercedesMe devices."""
|
|
||||||
|
|
||||||
def __init__(self, data, internal_name, sensor_name, vin, unit):
|
|
||||||
"""Initialize the MercedesMe entity."""
|
|
||||||
self._car = None
|
|
||||||
self._data = data
|
|
||||||
self._state = False
|
|
||||||
self._name = sensor_name
|
|
||||||
self._internal_name = internal_name
|
|
||||||
self._unit = unit
|
|
||||||
self._vin = vin
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the sensor."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
|
||||||
def async_added_to_hass(self):
|
|
||||||
"""Register callbacks."""
|
|
||||||
async_dispatcher_connect(
|
|
||||||
self.hass, SIGNAL_UPDATE_MERCEDESME, self._update_callback)
|
|
||||||
|
|
||||||
def _update_callback(self):
|
|
||||||
"""Callback update method."""
|
|
||||||
# If the method is made a callback this should be changed
|
|
||||||
# to the async version. Check core.callback
|
|
||||||
self.schedule_update_ha_state(True)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unit_of_measurement(self):
|
|
||||||
"""Return the unit of measurement."""
|
|
||||||
return self._unit
|
|
@ -1,87 +0,0 @@
|
|||||||
"""
|
|
||||||
Support for Mercedes cars with Mercedes ME.
|
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
|
||||||
https://home-assistant.io/components/sensor.mercedesme/
|
|
||||||
"""
|
|
||||||
import logging
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
from homeassistant.components.mercedesme import (
|
|
||||||
DATA_MME, FEATURE_NOT_AVAILABLE, MercedesMeEntity, SENSORS)
|
|
||||||
|
|
||||||
|
|
||||||
DEPENDENCIES = ['mercedesme']
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
|
||||||
"""Setup the sensor platform."""
|
|
||||||
if discovery_info is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
data = hass.data[DATA_MME].data
|
|
||||||
|
|
||||||
if not data.cars:
|
|
||||||
return
|
|
||||||
|
|
||||||
devices = []
|
|
||||||
for car in data.cars:
|
|
||||||
for key, value in sorted(SENSORS.items()):
|
|
||||||
if car['availabilities'].get(key, 'INVALID') == 'VALID':
|
|
||||||
devices.append(
|
|
||||||
MercedesMESensor(
|
|
||||||
data, key, value[0], car["vin"], value[1]))
|
|
||||||
else:
|
|
||||||
_LOGGER.warning(FEATURE_NOT_AVAILABLE, key, car["license"])
|
|
||||||
|
|
||||||
add_devices(devices, True)
|
|
||||||
|
|
||||||
|
|
||||||
class MercedesMESensor(MercedesMeEntity):
|
|
||||||
"""Representation of a Sensor."""
|
|
||||||
|
|
||||||
@property
|
|
||||||
def state(self):
|
|
||||||
"""Return the state of the sensor."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
"""Get the latest data and updates the states."""
|
|
||||||
_LOGGER.debug("Updating %s", self._internal_name)
|
|
||||||
|
|
||||||
self._car = next(
|
|
||||||
car for car in self._data.cars if car["vin"] == self._vin)
|
|
||||||
|
|
||||||
if self._internal_name == "latestTrip":
|
|
||||||
self._state = self._car["latestTrip"]["id"]
|
|
||||||
else:
|
|
||||||
self._state = self._car[self._internal_name]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_state_attributes(self):
|
|
||||||
"""Return the state attributes."""
|
|
||||||
if self._internal_name == "latestTrip":
|
|
||||||
return {
|
|
||||||
"duration_seconds":
|
|
||||||
self._car["latestTrip"]["durationSeconds"],
|
|
||||||
"distance_traveled_km":
|
|
||||||
self._car["latestTrip"]["distanceTraveledKm"],
|
|
||||||
"started_at": datetime.datetime.fromtimestamp(
|
|
||||||
self._car["latestTrip"]["startedAt"]
|
|
||||||
).strftime('%Y-%m-%d %H:%M:%S'),
|
|
||||||
"average_speed_km_per_hr":
|
|
||||||
self._car["latestTrip"]["averageSpeedKmPerHr"],
|
|
||||||
"finished": self._car["latestTrip"]["finished"],
|
|
||||||
"last_update": datetime.datetime.fromtimestamp(
|
|
||||||
self._car["lastUpdate"]
|
|
||||||
).strftime('%Y-%m-%d %H:%M:%S'),
|
|
||||||
"car": self._car["license"]
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
"last_update": datetime.datetime.fromtimestamp(
|
|
||||||
self._car["lastUpdate"]).strftime('%Y-%m-%d %H:%M:%S'),
|
|
||||||
"car": self._car["license"]
|
|
||||||
}
|
|
@ -495,9 +495,6 @@ matrix-client==0.0.6
|
|||||||
# homeassistant.components.maxcube
|
# homeassistant.components.maxcube
|
||||||
maxcube-api==0.1.0
|
maxcube-api==0.1.0
|
||||||
|
|
||||||
# homeassistant.components.mercedesme
|
|
||||||
mercedesmejsonpy==0.1.2
|
|
||||||
|
|
||||||
# homeassistant.components.notify.message_bird
|
# homeassistant.components.notify.message_bird
|
||||||
messagebird==1.2.0
|
messagebird==1.2.0
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user