Iterating the dictionary directly (#7251)
This commit is contained in:
parent
48eeb55198
commit
15b2473224
2 changed files with 9 additions and 10 deletions
|
@ -22,7 +22,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
hub.update_locks()
|
hub.update_locks()
|
||||||
locks.extend([
|
locks.extend([
|
||||||
VerisureDoorlock(device_id)
|
VerisureDoorlock(device_id)
|
||||||
for device_id in hub.lock_status.keys()
|
for device_id in hub.lock_status
|
||||||
])
|
])
|
||||||
add_devices(locks)
|
add_devices(locks)
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class VerisureDoorlock(LockDevice):
|
||||||
"""Representation of a Verisure doorlock."""
|
"""Representation of a Verisure doorlock."""
|
||||||
|
|
||||||
def __init__(self, device_id):
|
def __init__(self, device_id):
|
||||||
"""Initialize the lock."""
|
"""Initialize the Verisure lock."""
|
||||||
self._id = device_id
|
self._id = device_id
|
||||||
self._state = STATE_UNKNOWN
|
self._state = STATE_UNKNOWN
|
||||||
self._digits = hub.config.get(CONF_CODE_DIGITS)
|
self._digits = hub.config.get(CONF_CODE_DIGITS)
|
||||||
|
@ -72,8 +72,7 @@ class VerisureDoorlock(LockDevice):
|
||||||
self._state = STATE_LOCKED
|
self._state = STATE_LOCKED
|
||||||
elif hub.lock_status[self._id].status != 'pending':
|
elif hub.lock_status[self._id].status != 'pending':
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
'Unknown lock state %s',
|
"Unknown lock state %s", hub.lock_status[self._id].status)
|
||||||
hub.lock_status[self._id].status)
|
|
||||||
self._changed_by = hub.lock_status[self._id].name
|
self._changed_by = hub.lock_status[self._id].name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -84,13 +83,13 @@ class VerisureDoorlock(LockDevice):
|
||||||
def unlock(self, **kwargs):
|
def unlock(self, **kwargs):
|
||||||
"""Send unlock command."""
|
"""Send unlock command."""
|
||||||
hub.my_pages.lock.set(kwargs[ATTR_CODE], self._id, 'UNLOCKED')
|
hub.my_pages.lock.set(kwargs[ATTR_CODE], self._id, 'UNLOCKED')
|
||||||
_LOGGER.info('verisure doorlock unlocking')
|
_LOGGER.debug("Verisure doorlock unlocking")
|
||||||
hub.my_pages.lock.wait_while_pending()
|
hub.my_pages.lock.wait_while_pending()
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def lock(self, **kwargs):
|
def lock(self, **kwargs):
|
||||||
"""Send lock command."""
|
"""Send lock command."""
|
||||||
hub.my_pages.lock.set(kwargs[ATTR_CODE], self._id, 'LOCKED')
|
hub.my_pages.lock.set(kwargs[ATTR_CODE], self._id, 'LOCKED')
|
||||||
_LOGGER.info('verisure doorlock locking')
|
_LOGGER.debug("Verisure doorlock locking")
|
||||||
hub.my_pages.lock.wait_while_pending()
|
hub.my_pages.lock.wait_while_pending()
|
||||||
self.update()
|
self.update()
|
||||||
|
|
|
@ -47,8 +47,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the LG TV platform."""
|
"""Setup the LG TV platform."""
|
||||||
from pylgnetcast import LgNetCastClient
|
from pylgnetcast import LgNetCastClient
|
||||||
client = LgNetCastClient(config.get(CONF_HOST),
|
client = LgNetCastClient(
|
||||||
config.get(CONF_ACCESS_TOKEN))
|
config.get(CONF_HOST), config.get(CONF_ACCESS_TOKEN))
|
||||||
|
|
||||||
add_devices([LgTVDevice(client, config[CONF_NAME])])
|
add_devices([LgTVDevice(client, config[CONF_NAME])])
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ class LgTVDevice(MediaPlayerDevice):
|
||||||
self._sources = dict(zip(channel_names, channel_list))
|
self._sources = dict(zip(channel_names, channel_list))
|
||||||
# sort source names by the major channel number
|
# sort source names by the major channel number
|
||||||
source_tuples = [(k, self._sources[k].find('major').text)
|
source_tuples = [(k, self._sources[k].find('major').text)
|
||||||
for k in self._sources.keys()]
|
for k in self._sources]
|
||||||
sorted_sources = sorted(
|
sorted_sources = sorted(
|
||||||
source_tuples, key=lambda channel: int(channel[1]))
|
source_tuples, key=lambda channel: int(channel[1]))
|
||||||
self._source_names = [n for n, k in sorted_sources]
|
self._source_names = [n for n, k in sorted_sources]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue