HomeKit Alarm Control Panel Code Exception Fix (#14025)

* Catch exception for KeyError
* Use get and added test
This commit is contained in:
Matt Schmitt 2018-04-21 10:16:46 -04:00 committed by cdce8p
parent 4c23a61853
commit 51f55bddb7
2 changed files with 11 additions and 3 deletions

View File

@ -30,7 +30,7 @@ class SecuritySystem(HomeAccessory):
def __init__(self, *args, config): def __init__(self, *args, config):
"""Initialize a SecuritySystem accessory object.""" """Initialize a SecuritySystem accessory object."""
super().__init__(*args, category=CATEGORY_ALARM_SYSTEM) super().__init__(*args, category=CATEGORY_ALARM_SYSTEM)
self._alarm_code = config[ATTR_CODE] self._alarm_code = config.get(ATTR_CODE)
self.flag_target_state = False self.flag_target_state = False
serv_alarm = add_preload_service(self, SERV_SECURITY_SYSTEM) serv_alarm = add_preload_service(self, SERV_SECURITY_SYSTEM)

View File

@ -109,8 +109,16 @@ class TestHomekitSecuritySystems(unittest.TestCase):
acc = SecuritySystem(self.hass, 'SecuritySystem', acp, acc = SecuritySystem(self.hass, 'SecuritySystem', acp,
2, config={ATTR_CODE: None}) 2, config={ATTR_CODE: None})
acc.run() # Set from HomeKit
acc.char_target_state.client_update_value(0)
self.hass.block_till_done()
self.assertEqual(
self.events[0].data[ATTR_SERVICE], 'alarm_arm_home')
self.assertNotIn(ATTR_CODE, self.events[0].data[ATTR_SERVICE_DATA])
self.assertEqual(acc.char_target_state.value, 0)
acc = SecuritySystem(self.hass, 'SecuritySystem', acp,
2, config={})
# Set from HomeKit # Set from HomeKit
acc.char_target_state.client_update_value(0) acc.char_target_state.client_update_value(0)
self.hass.block_till_done() self.hass.block_till_done()