renamed add_devices to async_add_devices according to hass naming scheme (#9485)
* renamed add_devices to async_add_devices according to hass naming scheme * replaced some occurencies of async_add_entites to async_add_devices * fixed unit test * fixed unit test
This commit is contained in:
parent
185ada2354
commit
a5a970709f
12 changed files with 55 additions and 57 deletions
|
@ -27,20 +27,20 @@ def _get_alarm_state(spc_mode):
|
|||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_entities,
|
||||
def async_setup_platform(hass, config, async_add_devices,
|
||||
discovery_info=None):
|
||||
"""Set up the SPC alarm control panel platform."""
|
||||
if (discovery_info is None or
|
||||
discovery_info[ATTR_DISCOVER_AREAS] is None):
|
||||
return
|
||||
|
||||
entities = [SpcAlarm(hass=hass,
|
||||
area_id=area['id'],
|
||||
name=area['name'],
|
||||
state=_get_alarm_state(area['mode']))
|
||||
for area in discovery_info[ATTR_DISCOVER_AREAS]]
|
||||
devices = [SpcAlarm(hass=hass,
|
||||
area_id=area['id'],
|
||||
name=area['name'],
|
||||
state=_get_alarm_state(area['mode']))
|
||||
for area in discovery_info[ATTR_DISCOVER_AREAS]]
|
||||
|
||||
async_add_entities(entities)
|
||||
async_add_devices(devices)
|
||||
|
||||
|
||||
class SpcAlarm(alarm.AlarmControlPanel):
|
||||
|
|
|
@ -53,7 +53,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, add_devices,
|
||||
def async_setup_platform(hass, config, async_add_devices,
|
||||
discovery_info=None):
|
||||
"""Set up binary sensor(s) for KNX platform."""
|
||||
if DATA_KNX not in hass.data \
|
||||
|
@ -61,25 +61,25 @@ def async_setup_platform(hass, config, add_devices,
|
|||
return False
|
||||
|
||||
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:
|
||||
async_add_devices_config(hass, config, add_devices)
|
||||
async_add_devices_config(hass, config, async_add_devices)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@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."""
|
||||
entities = []
|
||||
for device_name in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||
device = hass.data[DATA_KNX].xknx.devices[device_name]
|
||||
entities.append(KNXBinarySensor(hass, device))
|
||||
add_devices(entities)
|
||||
async_add_devices(entities)
|
||||
|
||||
|
||||
@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."""
|
||||
name = config.get(CONF_NAME)
|
||||
import xknx
|
||||
|
@ -101,7 +101,7 @@ def async_add_devices_config(hass, config, add_devices):
|
|||
entity.automations.append(KNXAutomation(
|
||||
hass=hass, device=binary_sensor, hook=hook,
|
||||
action=action, counter=counter))
|
||||
add_devices([entity])
|
||||
async_add_devices([entity])
|
||||
|
||||
|
||||
class KNXBinarySensor(BinarySensorDevice):
|
||||
|
|
|
@ -41,14 +41,14 @@ def _create_sensor(hass, zone):
|
|||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_entities,
|
||||
def async_setup_platform(hass, config, async_add_devices,
|
||||
discovery_info=None):
|
||||
"""Initialize the platform."""
|
||||
if (discovery_info is None or
|
||||
discovery_info[ATTR_DISCOVER_DEVICES] is None):
|
||||
return
|
||||
|
||||
async_add_entities(
|
||||
async_add_devices(
|
||||
_create_sensor(hass, zone)
|
||||
for zone in discovery_info[ATTR_DISCOVER_DEVICES]
|
||||
if _get_device_class(zone['type']))
|
||||
|
|
|
@ -44,7 +44,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, add_devices,
|
||||
def async_setup_platform(hass, config, async_add_devices,
|
||||
discovery_info=None):
|
||||
"""Set up climate(s) for KNX platform."""
|
||||
if DATA_KNX not in hass.data \
|
||||
|
@ -52,25 +52,25 @@ def async_setup_platform(hass, config, add_devices,
|
|||
return False
|
||||
|
||||
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:
|
||||
async_add_devices_config(hass, config, add_devices)
|
||||
async_add_devices_config(hass, config, async_add_devices)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@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."""
|
||||
entities = []
|
||||
for device_name in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||
device = hass.data[DATA_KNX].xknx.devices[device_name]
|
||||
entities.append(KNXClimate(hass, device))
|
||||
add_devices(entities)
|
||||
async_add_devices(entities)
|
||||
|
||||
|
||||
@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."""
|
||||
import xknx
|
||||
climate = xknx.devices.Climate(
|
||||
|
@ -97,7 +97,7 @@ def async_add_devices_config(hass, config, add_devices):
|
|||
group_address_operation_mode_comfort=config.get(
|
||||
CONF_OPERATION_MODE_COMFORT_ADDRESS))
|
||||
hass.data[DATA_KNX].xknx.devices.add(climate)
|
||||
add_devices([KNXClimate(hass, climate)])
|
||||
async_add_devices([KNXClimate(hass, climate)])
|
||||
|
||||
|
||||
class KNXClimate(ClimateDevice):
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 73289bca6d4e326de4484e991019e10f69a351ed
|
||||
Subproject commit 07d5d6e8a9205f77f83f68615695bcbc73cf83e3
|
|
@ -32,7 +32,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, add_devices,
|
||||
def async_setup_platform(hass, config, async_add_devices,
|
||||
discovery_info=None):
|
||||
"""Set up light(s) for KNX platform."""
|
||||
if DATA_KNX not in hass.data \
|
||||
|
@ -40,25 +40,25 @@ def async_setup_platform(hass, config, add_devices,
|
|||
return False
|
||||
|
||||
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:
|
||||
async_add_devices_config(hass, config, add_devices)
|
||||
async_add_devices_config(hass, config, async_add_devices)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@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."""
|
||||
entities = []
|
||||
for device_name in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||
device = hass.data[DATA_KNX].xknx.devices[device_name]
|
||||
entities.append(KNXLight(hass, device))
|
||||
add_devices(entities)
|
||||
async_add_devices(entities)
|
||||
|
||||
|
||||
@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."""
|
||||
import xknx
|
||||
light = xknx.devices.Light(
|
||||
|
@ -70,7 +70,7 @@ def async_add_devices_config(hass, config, add_devices):
|
|||
group_address_brightness_state=config.get(
|
||||
CONF_BRIGHTNESS_STATE_ADDRESS))
|
||||
hass.data[DATA_KNX].xknx.devices.add(light)
|
||||
add_devices([KNXLight(hass, light)])
|
||||
async_add_devices([KNXLight(hass, light)])
|
||||
|
||||
|
||||
class KNXLight(Light):
|
||||
|
|
|
@ -129,7 +129,7 @@ def async_citybikes_request(hass, uri, schema):
|
|||
|
||||
# pylint: disable=unused-argument
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_entities,
|
||||
def async_setup_platform(hass, config, async_add_devices,
|
||||
discovery_info=None):
|
||||
"""Set up the CityBikes platform."""
|
||||
if DOMAIN not in hass.data:
|
||||
|
@ -159,7 +159,7 @@ def async_setup_platform(hass, config, async_add_entities,
|
|||
|
||||
yield from network.ready.wait()
|
||||
|
||||
entities = []
|
||||
devices = []
|
||||
for station in network.stations:
|
||||
dist = location.distance(latitude, longitude,
|
||||
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,
|
||||
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:
|
||||
|
|
|
@ -28,7 +28,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, add_devices,
|
||||
def async_setup_platform(hass, config, async_add_devices,
|
||||
discovery_info=None):
|
||||
"""Set up sensor(s) for KNX platform."""
|
||||
if DATA_KNX not in hass.data \
|
||||
|
@ -36,25 +36,25 @@ def async_setup_platform(hass, config, add_devices,
|
|||
return False
|
||||
|
||||
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:
|
||||
async_add_devices_config(hass, config, add_devices)
|
||||
async_add_devices_config(hass, config, async_add_devices)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@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."""
|
||||
entities = []
|
||||
for device_name in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||
device = hass.data[DATA_KNX].xknx.devices[device_name]
|
||||
entities.append(KNXSensor(hass, device))
|
||||
add_devices(entities)
|
||||
async_add_devices(entities)
|
||||
|
||||
|
||||
@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."""
|
||||
import xknx
|
||||
sensor = xknx.devices.Sensor(
|
||||
|
@ -63,7 +63,7 @@ def async_add_devices_config(hass, config, add_devices):
|
|||
group_address=config.get(CONF_ADDRESS),
|
||||
value_type=config.get(CONF_TYPE))
|
||||
hass.data[DATA_KNX].xknx.devices.add(sensor)
|
||||
add_devices([KNXSensor(hass, sensor)])
|
||||
async_add_devices([KNXSensor(hass, sensor)])
|
||||
|
||||
|
||||
class KNXSensor(Entity):
|
||||
|
|
|
@ -51,11 +51,11 @@ ERROR_STATE = [
|
|||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_entities,
|
||||
def async_setup_platform(hass, config, async_add_devices,
|
||||
discovery_info=None):
|
||||
"""Set up the Worx Landroid sensors."""
|
||||
for typ in ('battery', 'state'):
|
||||
async_add_entities([WorxLandroidSensor(typ, config)])
|
||||
async_add_devices([WorxLandroidSensor(typ, config)])
|
||||
|
||||
|
||||
class WorxLandroidSensor(Entity):
|
||||
|
@ -86,8 +86,7 @@ class WorxLandroidSensor(Entity):
|
|||
"""Return the unit of measurement of the sensor."""
|
||||
if self.sensor == 'battery':
|
||||
return '%'
|
||||
else:
|
||||
return None
|
||||
return None
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_update(self):
|
||||
|
@ -159,7 +158,6 @@ class WorxLandroidSensor(Entity):
|
|||
return 'charging-complete'
|
||||
elif state_obj[15] == 1:
|
||||
return 'going-home'
|
||||
else:
|
||||
return 'mowing'
|
||||
return 'mowing'
|
||||
|
||||
return state
|
||||
|
|
|
@ -27,7 +27,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, add_devices,
|
||||
def async_setup_platform(hass, config, async_add_devices,
|
||||
discovery_info=None):
|
||||
"""Set up switch(es) for KNX platform."""
|
||||
if DATA_KNX not in hass.data \
|
||||
|
@ -35,25 +35,25 @@ def async_setup_platform(hass, config, add_devices,
|
|||
return False
|
||||
|
||||
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:
|
||||
async_add_devices_config(hass, config, add_devices)
|
||||
async_add_devices_config(hass, config, async_add_devices)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@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."""
|
||||
entities = []
|
||||
for device_name in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||
device = hass.data[DATA_KNX].xknx.devices[device_name]
|
||||
entities.append(KNXSwitch(hass, device))
|
||||
add_devices(entities)
|
||||
async_add_devices(entities)
|
||||
|
||||
|
||||
@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."""
|
||||
import xknx
|
||||
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_state=config.get(CONF_STATE_ADDRESS))
|
||||
hass.data[DATA_KNX].xknx.devices.add(switch)
|
||||
add_devices([KNXSwitch(hass, switch)])
|
||||
async_add_devices([KNXSwitch(hass, switch)])
|
||||
|
||||
|
||||
class KNXSwitch(SwitchDevice):
|
||||
|
|
|
@ -54,7 +54,7 @@ def test_setup_platform(hass):
|
|||
|
||||
yield from spc.async_setup_platform(hass=hass,
|
||||
config={},
|
||||
async_add_entities=add_entities,
|
||||
async_add_devices=add_entities,
|
||||
discovery_info=areas)
|
||||
|
||||
assert len(added_entities) == 2
|
||||
|
|
|
@ -54,7 +54,7 @@ def test_setup_platform(hass):
|
|||
|
||||
yield from spc.async_setup_platform(hass=hass,
|
||||
config={},
|
||||
async_add_entities=add_entities,
|
||||
async_add_devices=add_entities,
|
||||
discovery_info=zones)
|
||||
|
||||
assert len(added_entities) == 3
|
||||
|
|
Loading…
Add table
Reference in a new issue