renamed add_devices to async_add_devices according to hass naming scheme (second try after failed #9485) (#9505)
This commit is contained in:
parent
3dbf951086
commit
a5155a2609
11 changed files with 54 additions and 56 deletions
|
@ -27,20 +27,20 @@ def _get_alarm_state(spc_mode):
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_setup_platform(hass, config, async_add_entities,
|
def async_setup_platform(hass, config, async_add_devices,
|
||||||
discovery_info=None):
|
discovery_info=None):
|
||||||
"""Set up the SPC alarm control panel platform."""
|
"""Set up the SPC alarm control panel platform."""
|
||||||
if (discovery_info is None or
|
if (discovery_info is None or
|
||||||
discovery_info[ATTR_DISCOVER_AREAS] is None):
|
discovery_info[ATTR_DISCOVER_AREAS] is None):
|
||||||
return
|
return
|
||||||
|
|
||||||
entities = [SpcAlarm(hass=hass,
|
devices = [SpcAlarm(hass=hass,
|
||||||
area_id=area['id'],
|
area_id=area['id'],
|
||||||
name=area['name'],
|
name=area['name'],
|
||||||
state=_get_alarm_state(area['mode']))
|
state=_get_alarm_state(area['mode']))
|
||||||
for area in discovery_info[ATTR_DISCOVER_AREAS]]
|
for area in discovery_info[ATTR_DISCOVER_AREAS]]
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_devices(devices)
|
||||||
|
|
||||||
|
|
||||||
class SpcAlarm(alarm.AlarmControlPanel):
|
class SpcAlarm(alarm.AlarmControlPanel):
|
||||||
|
|
|
@ -53,7 +53,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_setup_platform(hass, config, add_devices,
|
def async_setup_platform(hass, config, async_add_devices,
|
||||||
discovery_info=None):
|
discovery_info=None):
|
||||||
"""Set up binary sensor(s) for KNX platform."""
|
"""Set up binary sensor(s) for KNX platform."""
|
||||||
if DATA_KNX not in hass.data \
|
if DATA_KNX not in hass.data \
|
||||||
|
@ -61,25 +61,25 @@ def async_setup_platform(hass, config, add_devices,
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if discovery_info is not None:
|
if discovery_info is not None:
|
||||||
async_add_devices_discovery(hass, discovery_info, add_devices)
|
async_add_devices_discovery(hass, discovery_info, async_add_devices)
|
||||||
else:
|
else:
|
||||||
async_add_devices_config(hass, config, add_devices)
|
async_add_devices_config(hass, config, async_add_devices)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_devices_discovery(hass, discovery_info, add_devices):
|
def async_add_devices_discovery(hass, discovery_info, async_add_devices):
|
||||||
"""Set up binary sensors for KNX platform configured via xknx.yaml."""
|
"""Set up binary sensors for KNX platform configured via xknx.yaml."""
|
||||||
entities = []
|
entities = []
|
||||||
for device_name in discovery_info[ATTR_DISCOVER_DEVICES]:
|
for device_name in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||||
device = hass.data[DATA_KNX].xknx.devices[device_name]
|
device = hass.data[DATA_KNX].xknx.devices[device_name]
|
||||||
entities.append(KNXBinarySensor(hass, device))
|
entities.append(KNXBinarySensor(hass, device))
|
||||||
add_devices(entities)
|
async_add_devices(entities)
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_devices_config(hass, config, add_devices):
|
def async_add_devices_config(hass, config, async_add_devices):
|
||||||
"""Set up binary senor for KNX platform configured within plattform."""
|
"""Set up binary senor for KNX platform configured within plattform."""
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
import xknx
|
import xknx
|
||||||
|
@ -101,7 +101,7 @@ def async_add_devices_config(hass, config, add_devices):
|
||||||
entity.automations.append(KNXAutomation(
|
entity.automations.append(KNXAutomation(
|
||||||
hass=hass, device=binary_sensor, hook=hook,
|
hass=hass, device=binary_sensor, hook=hook,
|
||||||
action=action, counter=counter))
|
action=action, counter=counter))
|
||||||
add_devices([entity])
|
async_add_devices([entity])
|
||||||
|
|
||||||
|
|
||||||
class KNXBinarySensor(BinarySensorDevice):
|
class KNXBinarySensor(BinarySensorDevice):
|
||||||
|
|
|
@ -41,14 +41,14 @@ def _create_sensor(hass, zone):
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_setup_platform(hass, config, async_add_entities,
|
def async_setup_platform(hass, config, async_add_devices,
|
||||||
discovery_info=None):
|
discovery_info=None):
|
||||||
"""Initialize the platform."""
|
"""Initialize the platform."""
|
||||||
if (discovery_info is None or
|
if (discovery_info is None or
|
||||||
discovery_info[ATTR_DISCOVER_DEVICES] is None):
|
discovery_info[ATTR_DISCOVER_DEVICES] is None):
|
||||||
return
|
return
|
||||||
|
|
||||||
async_add_entities(
|
async_add_devices(
|
||||||
_create_sensor(hass, zone)
|
_create_sensor(hass, zone)
|
||||||
for zone in discovery_info[ATTR_DISCOVER_DEVICES]
|
for zone in discovery_info[ATTR_DISCOVER_DEVICES]
|
||||||
if _get_device_class(zone['type']))
|
if _get_device_class(zone['type']))
|
||||||
|
|
|
@ -44,7 +44,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_setup_platform(hass, config, add_devices,
|
def async_setup_platform(hass, config, async_add_devices,
|
||||||
discovery_info=None):
|
discovery_info=None):
|
||||||
"""Set up climate(s) for KNX platform."""
|
"""Set up climate(s) for KNX platform."""
|
||||||
if DATA_KNX not in hass.data \
|
if DATA_KNX not in hass.data \
|
||||||
|
@ -52,25 +52,25 @@ def async_setup_platform(hass, config, add_devices,
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if discovery_info is not None:
|
if discovery_info is not None:
|
||||||
async_add_devices_discovery(hass, discovery_info, add_devices)
|
async_add_devices_discovery(hass, discovery_info, async_add_devices)
|
||||||
else:
|
else:
|
||||||
async_add_devices_config(hass, config, add_devices)
|
async_add_devices_config(hass, config, async_add_devices)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_devices_discovery(hass, discovery_info, add_devices):
|
def async_add_devices_discovery(hass, discovery_info, async_add_devices):
|
||||||
"""Set up climates for KNX platform configured within plattform."""
|
"""Set up climates for KNX platform configured within plattform."""
|
||||||
entities = []
|
entities = []
|
||||||
for device_name in discovery_info[ATTR_DISCOVER_DEVICES]:
|
for device_name in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||||
device = hass.data[DATA_KNX].xknx.devices[device_name]
|
device = hass.data[DATA_KNX].xknx.devices[device_name]
|
||||||
entities.append(KNXClimate(hass, device))
|
entities.append(KNXClimate(hass, device))
|
||||||
add_devices(entities)
|
async_add_devices(entities)
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_devices_config(hass, config, add_devices):
|
def async_add_devices_config(hass, config, async_add_devices):
|
||||||
"""Set up climate for KNX platform configured within plattform."""
|
"""Set up climate for KNX platform configured within plattform."""
|
||||||
import xknx
|
import xknx
|
||||||
climate = xknx.devices.Climate(
|
climate = xknx.devices.Climate(
|
||||||
|
@ -97,7 +97,7 @@ def async_add_devices_config(hass, config, add_devices):
|
||||||
group_address_operation_mode_comfort=config.get(
|
group_address_operation_mode_comfort=config.get(
|
||||||
CONF_OPERATION_MODE_COMFORT_ADDRESS))
|
CONF_OPERATION_MODE_COMFORT_ADDRESS))
|
||||||
hass.data[DATA_KNX].xknx.devices.add(climate)
|
hass.data[DATA_KNX].xknx.devices.add(climate)
|
||||||
add_devices([KNXClimate(hass, climate)])
|
async_add_devices([KNXClimate(hass, climate)])
|
||||||
|
|
||||||
|
|
||||||
class KNXClimate(ClimateDevice):
|
class KNXClimate(ClimateDevice):
|
||||||
|
|
|
@ -32,7 +32,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_setup_platform(hass, config, add_devices,
|
def async_setup_platform(hass, config, async_add_devices,
|
||||||
discovery_info=None):
|
discovery_info=None):
|
||||||
"""Set up light(s) for KNX platform."""
|
"""Set up light(s) for KNX platform."""
|
||||||
if DATA_KNX not in hass.data \
|
if DATA_KNX not in hass.data \
|
||||||
|
@ -40,25 +40,25 @@ def async_setup_platform(hass, config, add_devices,
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if discovery_info is not None:
|
if discovery_info is not None:
|
||||||
async_add_devices_discovery(hass, discovery_info, add_devices)
|
async_add_devices_discovery(hass, discovery_info, async_add_devices)
|
||||||
else:
|
else:
|
||||||
async_add_devices_config(hass, config, add_devices)
|
async_add_devices_config(hass, config, async_add_devices)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_devices_discovery(hass, discovery_info, add_devices):
|
def async_add_devices_discovery(hass, discovery_info, async_add_devices):
|
||||||
"""Set up lights for KNX platform configured via xknx.yaml."""
|
"""Set up lights for KNX platform configured via xknx.yaml."""
|
||||||
entities = []
|
entities = []
|
||||||
for device_name in discovery_info[ATTR_DISCOVER_DEVICES]:
|
for device_name in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||||
device = hass.data[DATA_KNX].xknx.devices[device_name]
|
device = hass.data[DATA_KNX].xknx.devices[device_name]
|
||||||
entities.append(KNXLight(hass, device))
|
entities.append(KNXLight(hass, device))
|
||||||
add_devices(entities)
|
async_add_devices(entities)
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_devices_config(hass, config, add_devices):
|
def async_add_devices_config(hass, config, async_add_devices):
|
||||||
"""Set up light for KNX platform configured within plattform."""
|
"""Set up light for KNX platform configured within plattform."""
|
||||||
import xknx
|
import xknx
|
||||||
light = xknx.devices.Light(
|
light = xknx.devices.Light(
|
||||||
|
@ -70,7 +70,7 @@ def async_add_devices_config(hass, config, add_devices):
|
||||||
group_address_brightness_state=config.get(
|
group_address_brightness_state=config.get(
|
||||||
CONF_BRIGHTNESS_STATE_ADDRESS))
|
CONF_BRIGHTNESS_STATE_ADDRESS))
|
||||||
hass.data[DATA_KNX].xknx.devices.add(light)
|
hass.data[DATA_KNX].xknx.devices.add(light)
|
||||||
add_devices([KNXLight(hass, light)])
|
async_add_devices([KNXLight(hass, light)])
|
||||||
|
|
||||||
|
|
||||||
class KNXLight(Light):
|
class KNXLight(Light):
|
||||||
|
|
|
@ -129,7 +129,7 @@ def async_citybikes_request(hass, uri, schema):
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_setup_platform(hass, config, async_add_entities,
|
def async_setup_platform(hass, config, async_add_devices,
|
||||||
discovery_info=None):
|
discovery_info=None):
|
||||||
"""Set up the CityBikes platform."""
|
"""Set up the CityBikes platform."""
|
||||||
if DOMAIN not in hass.data:
|
if DOMAIN not in hass.data:
|
||||||
|
@ -159,7 +159,7 @@ def async_setup_platform(hass, config, async_add_entities,
|
||||||
|
|
||||||
yield from network.ready.wait()
|
yield from network.ready.wait()
|
||||||
|
|
||||||
entities = []
|
devices = []
|
||||||
for station in network.stations:
|
for station in network.stations:
|
||||||
dist = location.distance(latitude, longitude,
|
dist = location.distance(latitude, longitude,
|
||||||
station[ATTR_LATITUDE],
|
station[ATTR_LATITUDE],
|
||||||
|
@ -169,9 +169,9 @@ def async_setup_platform(hass, config, async_add_entities,
|
||||||
|
|
||||||
if radius > dist or stations_list.intersection((station_id,
|
if radius > dist or stations_list.intersection((station_id,
|
||||||
station_uid)):
|
station_uid)):
|
||||||
entities.append(CityBikesStation(network, station_id, name))
|
devices.append(CityBikesStation(network, station_id, name))
|
||||||
|
|
||||||
async_add_entities(entities, True)
|
async_add_devices(devices, True)
|
||||||
|
|
||||||
|
|
||||||
class CityBikesNetwork:
|
class CityBikesNetwork:
|
||||||
|
|
|
@ -28,7 +28,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_setup_platform(hass, config, add_devices,
|
def async_setup_platform(hass, config, async_add_devices,
|
||||||
discovery_info=None):
|
discovery_info=None):
|
||||||
"""Set up sensor(s) for KNX platform."""
|
"""Set up sensor(s) for KNX platform."""
|
||||||
if DATA_KNX not in hass.data \
|
if DATA_KNX not in hass.data \
|
||||||
|
@ -36,25 +36,25 @@ def async_setup_platform(hass, config, add_devices,
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if discovery_info is not None:
|
if discovery_info is not None:
|
||||||
async_add_devices_discovery(hass, discovery_info, add_devices)
|
async_add_devices_discovery(hass, discovery_info, async_add_devices)
|
||||||
else:
|
else:
|
||||||
async_add_devices_config(hass, config, add_devices)
|
async_add_devices_config(hass, config, async_add_devices)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_devices_discovery(hass, discovery_info, add_devices):
|
def async_add_devices_discovery(hass, discovery_info, async_add_devices):
|
||||||
"""Set up sensors for KNX platform configured via xknx.yaml."""
|
"""Set up sensors for KNX platform configured via xknx.yaml."""
|
||||||
entities = []
|
entities = []
|
||||||
for device_name in discovery_info[ATTR_DISCOVER_DEVICES]:
|
for device_name in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||||
device = hass.data[DATA_KNX].xknx.devices[device_name]
|
device = hass.data[DATA_KNX].xknx.devices[device_name]
|
||||||
entities.append(KNXSensor(hass, device))
|
entities.append(KNXSensor(hass, device))
|
||||||
add_devices(entities)
|
async_add_devices(entities)
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_devices_config(hass, config, add_devices):
|
def async_add_devices_config(hass, config, async_add_devices):
|
||||||
"""Set up sensor for KNX platform configured within plattform."""
|
"""Set up sensor for KNX platform configured within plattform."""
|
||||||
import xknx
|
import xknx
|
||||||
sensor = xknx.devices.Sensor(
|
sensor = xknx.devices.Sensor(
|
||||||
|
@ -63,7 +63,7 @@ def async_add_devices_config(hass, config, add_devices):
|
||||||
group_address=config.get(CONF_ADDRESS),
|
group_address=config.get(CONF_ADDRESS),
|
||||||
value_type=config.get(CONF_TYPE))
|
value_type=config.get(CONF_TYPE))
|
||||||
hass.data[DATA_KNX].xknx.devices.add(sensor)
|
hass.data[DATA_KNX].xknx.devices.add(sensor)
|
||||||
add_devices([KNXSensor(hass, sensor)])
|
async_add_devices([KNXSensor(hass, sensor)])
|
||||||
|
|
||||||
|
|
||||||
class KNXSensor(Entity):
|
class KNXSensor(Entity):
|
||||||
|
|
|
@ -51,11 +51,11 @@ ERROR_STATE = [
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_setup_platform(hass, config, async_add_entities,
|
def async_setup_platform(hass, config, async_add_devices,
|
||||||
discovery_info=None):
|
discovery_info=None):
|
||||||
"""Set up the Worx Landroid sensors."""
|
"""Set up the Worx Landroid sensors."""
|
||||||
for typ in ('battery', 'state'):
|
for typ in ('battery', 'state'):
|
||||||
async_add_entities([WorxLandroidSensor(typ, config)])
|
async_add_devices([WorxLandroidSensor(typ, config)])
|
||||||
|
|
||||||
|
|
||||||
class WorxLandroidSensor(Entity):
|
class WorxLandroidSensor(Entity):
|
||||||
|
@ -86,8 +86,7 @@ class WorxLandroidSensor(Entity):
|
||||||
"""Return the unit of measurement of the sensor."""
|
"""Return the unit of measurement of the sensor."""
|
||||||
if self.sensor == 'battery':
|
if self.sensor == 'battery':
|
||||||
return '%'
|
return '%'
|
||||||
else:
|
return None
|
||||||
return None
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_update(self):
|
def async_update(self):
|
||||||
|
@ -159,7 +158,6 @@ class WorxLandroidSensor(Entity):
|
||||||
return 'charging-complete'
|
return 'charging-complete'
|
||||||
elif state_obj[15] == 1:
|
elif state_obj[15] == 1:
|
||||||
return 'going-home'
|
return 'going-home'
|
||||||
else:
|
return 'mowing'
|
||||||
return 'mowing'
|
|
||||||
|
|
||||||
return state
|
return state
|
||||||
|
|
|
@ -27,7 +27,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_setup_platform(hass, config, add_devices,
|
def async_setup_platform(hass, config, async_add_devices,
|
||||||
discovery_info=None):
|
discovery_info=None):
|
||||||
"""Set up switch(es) for KNX platform."""
|
"""Set up switch(es) for KNX platform."""
|
||||||
if DATA_KNX not in hass.data \
|
if DATA_KNX not in hass.data \
|
||||||
|
@ -35,25 +35,25 @@ def async_setup_platform(hass, config, add_devices,
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if discovery_info is not None:
|
if discovery_info is not None:
|
||||||
async_add_devices_discovery(hass, discovery_info, add_devices)
|
async_add_devices_discovery(hass, discovery_info, async_add_devices)
|
||||||
else:
|
else:
|
||||||
async_add_devices_config(hass, config, add_devices)
|
async_add_devices_config(hass, config, async_add_devices)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_devices_discovery(hass, discovery_info, add_devices):
|
def async_add_devices_discovery(hass, discovery_info, async_add_devices):
|
||||||
"""Set up switches for KNX platform configured via xknx.yaml."""
|
"""Set up switches for KNX platform configured via xknx.yaml."""
|
||||||
entities = []
|
entities = []
|
||||||
for device_name in discovery_info[ATTR_DISCOVER_DEVICES]:
|
for device_name in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||||
device = hass.data[DATA_KNX].xknx.devices[device_name]
|
device = hass.data[DATA_KNX].xknx.devices[device_name]
|
||||||
entities.append(KNXSwitch(hass, device))
|
entities.append(KNXSwitch(hass, device))
|
||||||
add_devices(entities)
|
async_add_devices(entities)
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_devices_config(hass, config, add_devices):
|
def async_add_devices_config(hass, config, async_add_devices):
|
||||||
"""Set up switch for KNX platform configured within plattform."""
|
"""Set up switch for KNX platform configured within plattform."""
|
||||||
import xknx
|
import xknx
|
||||||
switch = xknx.devices.Switch(
|
switch = xknx.devices.Switch(
|
||||||
|
@ -62,7 +62,7 @@ def async_add_devices_config(hass, config, add_devices):
|
||||||
group_address=config.get(CONF_ADDRESS),
|
group_address=config.get(CONF_ADDRESS),
|
||||||
group_address_state=config.get(CONF_STATE_ADDRESS))
|
group_address_state=config.get(CONF_STATE_ADDRESS))
|
||||||
hass.data[DATA_KNX].xknx.devices.add(switch)
|
hass.data[DATA_KNX].xknx.devices.add(switch)
|
||||||
add_devices([KNXSwitch(hass, switch)])
|
async_add_devices([KNXSwitch(hass, switch)])
|
||||||
|
|
||||||
|
|
||||||
class KNXSwitch(SwitchDevice):
|
class KNXSwitch(SwitchDevice):
|
||||||
|
|
|
@ -54,7 +54,7 @@ def test_setup_platform(hass):
|
||||||
|
|
||||||
yield from spc.async_setup_platform(hass=hass,
|
yield from spc.async_setup_platform(hass=hass,
|
||||||
config={},
|
config={},
|
||||||
async_add_entities=add_entities,
|
async_add_devices=add_entities,
|
||||||
discovery_info=areas)
|
discovery_info=areas)
|
||||||
|
|
||||||
assert len(added_entities) == 2
|
assert len(added_entities) == 2
|
||||||
|
|
|
@ -54,7 +54,7 @@ def test_setup_platform(hass):
|
||||||
|
|
||||||
yield from spc.async_setup_platform(hass=hass,
|
yield from spc.async_setup_platform(hass=hass,
|
||||||
config={},
|
config={},
|
||||||
async_add_entities=add_entities,
|
async_add_devices=add_entities,
|
||||||
discovery_info=zones)
|
discovery_info=zones)
|
||||||
|
|
||||||
assert len(added_entities) == 3
|
assert len(added_entities) == 3
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue