Fixed attribute configuration handling in universal media player

Forced all parsed attribute configurations to be of length 2. Removed
entity_id=None option from entity lookups. Explicitly passed entity
lookup information to _entity_lkp.
This commit is contained in:
Ryan Kraus 2016-01-12 21:02:39 -05:00 committed by Paulus Schoutsen
parent 07953fb7e3
commit a84429538b

View file

@ -130,7 +130,10 @@ def validate_attributes(config):
config[CONF_ATTRS] = {}
for key, val in config[CONF_ATTRS].items():
config[CONF_ATTRS][key] = val.split('|', 1)
attr = val.split('|', 1)
if len(attr) == 1:
attr.append(None)
config[CONF_ATTRS][key] = attr
class UniversalMediaPlayer(MediaPlayerDevice):
@ -152,11 +155,8 @@ class UniversalMediaPlayer(MediaPlayerDevice):
track_state_change(hass, depend, self.update_state)
def _entity_lkp(self, entity_id=None, state_attr=None):
def _entity_lkp(self, entity_id, state_attr=None):
""" Looks up an entity state from hass """
if entity_id is None:
return
state_obj = self.hass.states.get(entity_id)
if state_obj is None:
@ -169,7 +169,8 @@ class UniversalMediaPlayer(MediaPlayerDevice):
def _override_or_child_attr(self, attr_name):
""" returns either the override or the active child for attr_name """
if attr_name in self._attrs:
return self._entity_lkp(*self._attrs[attr_name])
return self._entity_lkp(self._attrs[attr_name][0],
self._attrs[attr_name][1])
return self._child_attr(attr_name)
@ -204,7 +205,8 @@ class UniversalMediaPlayer(MediaPlayerDevice):
def master_state(self):
""" gets the master state from entity or none """
if CONF_STATE in self._attrs:
master_state = self._entity_lkp(*self._attrs[CONF_STATE])
master_state = self._entity_lkp(self._attrs[CONF_STATE][0],
self._attrs[CONF_STATE][1])
return master_state if master_state else STATE_OFF
else:
return None