mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 00:07:10 +00:00
Fix MercedesMe - add check for unsupported features (#12342)
* Add check for unsupported features * Lint fix * change to guard clause
This commit is contained in:
parent
66d14da5e9
commit
00ff305bd7
@ -9,7 +9,7 @@ import datetime
|
||||
|
||||
from homeassistant.components.binary_sensor import (BinarySensorDevice)
|
||||
from homeassistant.components.mercedesme import (
|
||||
DATA_MME, MercedesMeEntity, BINARY_SENSORS)
|
||||
DATA_MME, FEATURE_NOT_AVAILABLE, MercedesMeEntity, BINARY_SENSORS)
|
||||
|
||||
DEPENDENCIES = ['mercedesme']
|
||||
|
||||
@ -27,8 +27,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
devices = []
|
||||
for car in data.cars:
|
||||
for key, value in sorted(BINARY_SENSORS.items()):
|
||||
devices.append(MercedesMEBinarySensor(
|
||||
data, key, value[0], car["vin"], None))
|
||||
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)
|
||||
|
||||
|
@ -49,10 +49,13 @@ class MercedesMEDeviceTracker(object):
|
||||
def update_info(self, now=None):
|
||||
"""Update the device info."""
|
||||
for device in self.data.cars:
|
||||
_LOGGER.debug("Updating %s", device["vin"])
|
||||
if not device['services'].get('VEHICLE_FINDER', False):
|
||||
continue
|
||||
|
||||
location = self.data.get_location(device["vin"])
|
||||
if location is None:
|
||||
return False
|
||||
continue
|
||||
|
||||
dev_id = device["vin"]
|
||||
name = device["license"]
|
||||
|
||||
|
@ -41,6 +41,8 @@ SENSORS = {
|
||||
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'
|
||||
|
||||
|
@ -8,7 +8,7 @@ import logging
|
||||
import datetime
|
||||
|
||||
from homeassistant.components.mercedesme import (
|
||||
DATA_MME, MercedesMeEntity, SENSORS)
|
||||
DATA_MME, FEATURE_NOT_AVAILABLE, MercedesMeEntity, SENSORS)
|
||||
|
||||
|
||||
DEPENDENCIES = ['mercedesme']
|
||||
@ -29,8 +29,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
devices = []
|
||||
for car in data.cars:
|
||||
for key, value in sorted(SENSORS.items()):
|
||||
devices.append(
|
||||
MercedesMESensor(data, key, value[0], car["vin"], value[1]))
|
||||
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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user