mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Changed the configuration to use hashes instead of searching array
This commit is contained in:
parent
7dc3198320
commit
95852db18d
@ -13,12 +13,10 @@ light:
|
||||
platform: vera
|
||||
vera_controller_url: http://YOUR_VERA_IP:3480/
|
||||
device_data:
|
||||
-
|
||||
vera_id: 12
|
||||
12:
|
||||
name: My awesome switch
|
||||
exclude: true
|
||||
-
|
||||
vera_id: 13
|
||||
13:
|
||||
name: Another switch
|
||||
|
||||
VARIABLES:
|
||||
@ -34,16 +32,12 @@ device_data
|
||||
*Optional
|
||||
This contains an array additional device info for your Vera devices. It is not
|
||||
required and if not specified all lights configured in your Vera controller
|
||||
will be added with default values.
|
||||
will be added with default values. You should use the id of your vera device
|
||||
as the key for the device within device_data
|
||||
|
||||
|
||||
These are the variables for the device_data array:
|
||||
|
||||
vera_id
|
||||
*Required
|
||||
The Vera device id you wish these configuration options to be applied to
|
||||
|
||||
|
||||
name
|
||||
*Optional
|
||||
This parameter allows you to override the name of your Vera device in the HA
|
||||
@ -77,7 +71,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
)
|
||||
return False
|
||||
|
||||
device_data = config.get('device_data', None)
|
||||
device_data = config.get('device_data', {})
|
||||
|
||||
controller = veraApi.VeraController(base_url)
|
||||
devices = []
|
||||
@ -90,7 +84,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
|
||||
lights = []
|
||||
for device in devices:
|
||||
extra_data = get_extra_device_data(device_data, device.deviceId)
|
||||
extra_data = device_data.get(device.deviceId, None)
|
||||
exclude = False
|
||||
if extra_data:
|
||||
exclude = extra_data.get('exclude', False)
|
||||
@ -100,14 +94,3 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
|
||||
add_devices_callback(lights)
|
||||
|
||||
|
||||
def get_extra_device_data(device_data, device_id):
|
||||
""" Gets the additional configuration data by Vera device Id """
|
||||
if not device_data:
|
||||
return None
|
||||
|
||||
for item in device_data:
|
||||
if item.get('vera_id') == device_id:
|
||||
return item
|
||||
|
||||
return None
|
||||
|
@ -9,12 +9,10 @@ sensor:
|
||||
platform: vera
|
||||
vera_controller_url: http://YOUR_VERA_IP:3480/
|
||||
device_data:
|
||||
-
|
||||
vera_id: 12
|
||||
12:
|
||||
name: My awesome sensor
|
||||
exclude: true
|
||||
-
|
||||
vera_id: 13
|
||||
13:
|
||||
name: Another sensor
|
||||
|
||||
VARIABLES:
|
||||
@ -30,16 +28,11 @@ device_data
|
||||
*Optional
|
||||
This contains an array additional device info for your Vera devices. It is not
|
||||
required and if not specified all sensors configured in your Vera controller
|
||||
will be added with default values.
|
||||
|
||||
will be added with default values. You should use the id of your vera device
|
||||
as the key for the device within device_data
|
||||
|
||||
These are the variables for the device_data array:
|
||||
|
||||
vera_id
|
||||
*Required
|
||||
The Vera device id you wish these configuration options to be applied to
|
||||
|
||||
|
||||
name
|
||||
*Optional
|
||||
This parameter allows you to override the name of your Vera device in the HA
|
||||
@ -77,7 +70,7 @@ def get_devices(hass, config):
|
||||
)
|
||||
return False
|
||||
|
||||
device_data = config.get('device_data', None)
|
||||
device_data = config.get('device_data', {})
|
||||
|
||||
vera_controller = veraApi.VeraController(base_url)
|
||||
categories = ['Temperature Sensor', 'Light Sensor', 'Sensor']
|
||||
@ -91,7 +84,7 @@ def get_devices(hass, config):
|
||||
|
||||
vera_sensors = []
|
||||
for device in devices:
|
||||
extra_data = get_extra_device_data(device_data, device.deviceId)
|
||||
extra_data = device_data.get(device.deviceId, None)
|
||||
exclude = False
|
||||
if extra_data:
|
||||
exclude = extra_data.get('exclude', False)
|
||||
@ -107,17 +100,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
add_devices(get_devices(hass, config))
|
||||
|
||||
|
||||
def get_extra_device_data(device_data, device_id):
|
||||
""" Gets the additional configuration data by Vera device Id """
|
||||
if not device_data:
|
||||
return None
|
||||
|
||||
for item in device_data:
|
||||
if item.get('vera_id') == device_id:
|
||||
return item
|
||||
return None
|
||||
|
||||
|
||||
class VeraSensor(Device):
|
||||
""" Represents a Vera Sensor """
|
||||
extra_data = None
|
||||
@ -128,7 +110,8 @@ class VeraSensor(Device):
|
||||
self.extra_data = extra_data
|
||||
if self.extra_data and self.extra_data.get('name'):
|
||||
self._name = self.extra_data.get('name')
|
||||
self._name = self.vera_device.name
|
||||
else:
|
||||
self._name = self.vera_device.name
|
||||
|
||||
def __str__(self):
|
||||
return "%s %s %s" % (self.name, self.vera_device.deviceId, self.state)
|
||||
|
@ -9,12 +9,10 @@ switch:
|
||||
platform: vera
|
||||
vera_controller_url: http://YOUR_VERA_IP:3480/
|
||||
device_data:
|
||||
-
|
||||
vera_id: 12
|
||||
12:
|
||||
name: My awesome switch
|
||||
exclude: true
|
||||
-
|
||||
vera_id: 13
|
||||
13:
|
||||
name: Another Switch
|
||||
|
||||
VARIABLES:
|
||||
@ -30,15 +28,12 @@ device_data
|
||||
*Optional
|
||||
This contains an array additional device info for your Vera devices. It is not
|
||||
required and if not specified all lights configured in your Vera controller
|
||||
will be added with default values.
|
||||
will be added with default values. You should use the id of your vera device
|
||||
as the key for the device within device_data
|
||||
|
||||
|
||||
These are the variables for the device_data array:
|
||||
|
||||
vera_id
|
||||
*Required
|
||||
The Vera device id you wish these configuration options to be applied to
|
||||
|
||||
|
||||
name
|
||||
*Optional
|
||||
@ -77,7 +72,7 @@ def get_devices(hass, config):
|
||||
)
|
||||
return False
|
||||
|
||||
device_data = config.get('device_data', None)
|
||||
device_data = config.get('device_data', {})
|
||||
|
||||
vera_controller = veraApi.VeraController(base_url)
|
||||
devices = []
|
||||
@ -90,7 +85,7 @@ def get_devices(hass, config):
|
||||
|
||||
vera_switches = []
|
||||
for device in devices:
|
||||
extra_data = get_extra_device_data(device_data, device.deviceId)
|
||||
extra_data = device_data.get(device.deviceId, None)
|
||||
exclude = False
|
||||
if extra_data:
|
||||
exclude = extra_data.get('exclude', False)
|
||||
@ -101,17 +96,6 @@ def get_devices(hass, config):
|
||||
return vera_switches
|
||||
|
||||
|
||||
def get_extra_device_data(device_data, device_id):
|
||||
""" Gets the additional configuration data by Vera device Id """
|
||||
if not device_data:
|
||||
return None
|
||||
|
||||
for item in device_data:
|
||||
if item.get('vera_id') == device_id:
|
||||
return item
|
||||
return None
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Find and return Vera lights. """
|
||||
add_devices(get_devices(hass, config))
|
||||
@ -129,7 +113,8 @@ class VeraSwitch(ToggleDevice):
|
||||
self.extra_data = extra_data
|
||||
if self.extra_data and self.extra_data.get('name'):
|
||||
self._name = self.extra_data.get('name')
|
||||
self._name = self.vera_device.name
|
||||
else:
|
||||
self._name = self.vera_device.name
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user