mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +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
|
platform: vera
|
||||||
vera_controller_url: http://YOUR_VERA_IP:3480/
|
vera_controller_url: http://YOUR_VERA_IP:3480/
|
||||||
device_data:
|
device_data:
|
||||||
-
|
12:
|
||||||
vera_id: 12
|
|
||||||
name: My awesome switch
|
name: My awesome switch
|
||||||
exclude: true
|
exclude: true
|
||||||
-
|
13:
|
||||||
vera_id: 13
|
|
||||||
name: Another switch
|
name: Another switch
|
||||||
|
|
||||||
VARIABLES:
|
VARIABLES:
|
||||||
@ -34,16 +32,12 @@ device_data
|
|||||||
*Optional
|
*Optional
|
||||||
This contains an array additional device info for your Vera devices. It is not
|
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
|
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:
|
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
|
name
|
||||||
*Optional
|
*Optional
|
||||||
This parameter allows you to override the name of your Vera device in the HA
|
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
|
return False
|
||||||
|
|
||||||
device_data = config.get('device_data', None)
|
device_data = config.get('device_data', {})
|
||||||
|
|
||||||
controller = veraApi.VeraController(base_url)
|
controller = veraApi.VeraController(base_url)
|
||||||
devices = []
|
devices = []
|
||||||
@ -90,7 +84,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
|
|
||||||
lights = []
|
lights = []
|
||||||
for device in devices:
|
for device in devices:
|
||||||
extra_data = get_extra_device_data(device_data, device.deviceId)
|
extra_data = device_data.get(device.deviceId, None)
|
||||||
exclude = False
|
exclude = False
|
||||||
if extra_data:
|
if extra_data:
|
||||||
exclude = extra_data.get('exclude', False)
|
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)
|
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
|
platform: vera
|
||||||
vera_controller_url: http://YOUR_VERA_IP:3480/
|
vera_controller_url: http://YOUR_VERA_IP:3480/
|
||||||
device_data:
|
device_data:
|
||||||
-
|
12:
|
||||||
vera_id: 12
|
|
||||||
name: My awesome sensor
|
name: My awesome sensor
|
||||||
exclude: true
|
exclude: true
|
||||||
-
|
13:
|
||||||
vera_id: 13
|
|
||||||
name: Another sensor
|
name: Another sensor
|
||||||
|
|
||||||
VARIABLES:
|
VARIABLES:
|
||||||
@ -30,16 +28,11 @@ device_data
|
|||||||
*Optional
|
*Optional
|
||||||
This contains an array additional device info for your Vera devices. It is not
|
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
|
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:
|
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
|
name
|
||||||
*Optional
|
*Optional
|
||||||
This parameter allows you to override the name of your Vera device in the HA
|
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
|
return False
|
||||||
|
|
||||||
device_data = config.get('device_data', None)
|
device_data = config.get('device_data', {})
|
||||||
|
|
||||||
vera_controller = veraApi.VeraController(base_url)
|
vera_controller = veraApi.VeraController(base_url)
|
||||||
categories = ['Temperature Sensor', 'Light Sensor', 'Sensor']
|
categories = ['Temperature Sensor', 'Light Sensor', 'Sensor']
|
||||||
@ -91,7 +84,7 @@ def get_devices(hass, config):
|
|||||||
|
|
||||||
vera_sensors = []
|
vera_sensors = []
|
||||||
for device in devices:
|
for device in devices:
|
||||||
extra_data = get_extra_device_data(device_data, device.deviceId)
|
extra_data = device_data.get(device.deviceId, None)
|
||||||
exclude = False
|
exclude = False
|
||||||
if extra_data:
|
if extra_data:
|
||||||
exclude = extra_data.get('exclude', False)
|
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))
|
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):
|
class VeraSensor(Device):
|
||||||
""" Represents a Vera Sensor """
|
""" Represents a Vera Sensor """
|
||||||
extra_data = None
|
extra_data = None
|
||||||
@ -128,7 +110,8 @@ class VeraSensor(Device):
|
|||||||
self.extra_data = extra_data
|
self.extra_data = extra_data
|
||||||
if self.extra_data and self.extra_data.get('name'):
|
if self.extra_data and self.extra_data.get('name'):
|
||||||
self._name = 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):
|
def __str__(self):
|
||||||
return "%s %s %s" % (self.name, self.vera_device.deviceId, self.state)
|
return "%s %s %s" % (self.name, self.vera_device.deviceId, self.state)
|
||||||
|
@ -9,12 +9,10 @@ switch:
|
|||||||
platform: vera
|
platform: vera
|
||||||
vera_controller_url: http://YOUR_VERA_IP:3480/
|
vera_controller_url: http://YOUR_VERA_IP:3480/
|
||||||
device_data:
|
device_data:
|
||||||
-
|
12:
|
||||||
vera_id: 12
|
|
||||||
name: My awesome switch
|
name: My awesome switch
|
||||||
exclude: true
|
exclude: true
|
||||||
-
|
13:
|
||||||
vera_id: 13
|
|
||||||
name: Another Switch
|
name: Another Switch
|
||||||
|
|
||||||
VARIABLES:
|
VARIABLES:
|
||||||
@ -30,15 +28,12 @@ device_data
|
|||||||
*Optional
|
*Optional
|
||||||
This contains an array additional device info for your Vera devices. It is not
|
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
|
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:
|
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
|
name
|
||||||
*Optional
|
*Optional
|
||||||
@ -77,7 +72,7 @@ def get_devices(hass, config):
|
|||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
device_data = config.get('device_data', None)
|
device_data = config.get('device_data', {})
|
||||||
|
|
||||||
vera_controller = veraApi.VeraController(base_url)
|
vera_controller = veraApi.VeraController(base_url)
|
||||||
devices = []
|
devices = []
|
||||||
@ -90,7 +85,7 @@ def get_devices(hass, config):
|
|||||||
|
|
||||||
vera_switches = []
|
vera_switches = []
|
||||||
for device in devices:
|
for device in devices:
|
||||||
extra_data = get_extra_device_data(device_data, device.deviceId)
|
extra_data = device_data.get(device.deviceId, None)
|
||||||
exclude = False
|
exclude = False
|
||||||
if extra_data:
|
if extra_data:
|
||||||
exclude = extra_data.get('exclude', False)
|
exclude = extra_data.get('exclude', False)
|
||||||
@ -101,17 +96,6 @@ def get_devices(hass, config):
|
|||||||
return vera_switches
|
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):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
""" Find and return Vera lights. """
|
""" Find and return Vera lights. """
|
||||||
add_devices(get_devices(hass, config))
|
add_devices(get_devices(hass, config))
|
||||||
@ -129,7 +113,8 @@ class VeraSwitch(ToggleDevice):
|
|||||||
self.extra_data = extra_data
|
self.extra_data = extra_data
|
||||||
if self.extra_data and self.extra_data.get('name'):
|
if self.extra_data and self.extra_data.get('name'):
|
||||||
self._name = 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
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user