HomeKit: Bugfix & improved logging (#13431)
* Bugfix & improved logging * Removed logging statements * Removed logging testpull/13452/head
parent
55daea5169
commit
7db37a3834
|
@ -73,8 +73,6 @@ async def async_setup(hass, config):
|
|||
|
||||
def get_accessory(hass, state, aid, config):
|
||||
"""Take state and return an accessory object if supported."""
|
||||
_LOGGER.debug('<entity_id=%s aid=%d config=%s>',
|
||||
state.entity_id, aid, config)
|
||||
if not aid:
|
||||
_LOGGER.warning('The entitiy "%s" is not supported, since it '
|
||||
'generates an invalid aid, please change it.',
|
||||
|
@ -129,8 +127,6 @@ def get_accessory(hass, state, aid, config):
|
|||
_LOGGER.debug('Add "%s" as "%s"', state.entity_id, 'Switch')
|
||||
return TYPES['Switch'](hass, state.entity_id, state.name, aid=aid)
|
||||
|
||||
_LOGGER.warning('The entity "%s" is not supported yet',
|
||||
state.entity_id)
|
||||
return None
|
||||
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ class WindowCovering(HomeAccessory):
|
|||
|
||||
def move_cover(self, value):
|
||||
"""Move cover to value if call came from HomeKit."""
|
||||
self.char_target_position.set_value(value, should_callback=False)
|
||||
if value != self.current_position:
|
||||
_LOGGER.debug('%s: Set position to %d', self._entity_id, value)
|
||||
self.homekit_target = value
|
||||
|
|
|
@ -71,6 +71,7 @@ class Light(HomeAccessory):
|
|||
|
||||
_LOGGER.debug('%s: Set state to %d', self._entity_id, value)
|
||||
self._flag[CHAR_ON] = True
|
||||
self.char_on.set_value(value, should_callback=False)
|
||||
|
||||
if value == 1:
|
||||
self._hass.components.light.turn_on(self._entity_id)
|
||||
|
@ -81,6 +82,7 @@ class Light(HomeAccessory):
|
|||
"""Set brightness if call came from HomeKit."""
|
||||
_LOGGER.debug('%s: Set brightness to %d', self._entity_id, value)
|
||||
self._flag[CHAR_BRIGHTNESS] = True
|
||||
self.char_brightness.set_value(value, should_callback=False)
|
||||
self._hass.components.light.turn_on(
|
||||
self._entity_id, brightness_pct=value)
|
||||
|
||||
|
@ -88,6 +90,7 @@ class Light(HomeAccessory):
|
|||
"""Set saturation if call came from HomeKit."""
|
||||
_LOGGER.debug('%s: Set saturation to %d', self._entity_id, value)
|
||||
self._flag[CHAR_SATURATION] = True
|
||||
self.char_saturation.set_value(value, should_callback=False)
|
||||
self._saturation = value
|
||||
self.set_color()
|
||||
|
||||
|
@ -95,6 +98,7 @@ class Light(HomeAccessory):
|
|||
"""Set hue if call came from HomeKit."""
|
||||
_LOGGER.debug('%s: Set hue to %d', self._entity_id, value)
|
||||
self._flag[CHAR_HUE] = True
|
||||
self.char_hue.set_value(value, should_callback=False)
|
||||
self._hue = value
|
||||
self.set_color()
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ class SecuritySystem(HomeAccessory):
|
|||
_LOGGER.debug('%s: Set security state to %d',
|
||||
self._entity_id, value)
|
||||
self.flag_target_state = True
|
||||
self.char_target_state.set_value(value, should_callback=False)
|
||||
hass_value = HOMEKIT_TO_HASS[value]
|
||||
service = STATE_TO_SERVICE[hass_value]
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ class Switch(HomeAccessory):
|
|||
_LOGGER.debug('%s: Set switch state to %s',
|
||||
self._entity_id, value)
|
||||
self.flag_target_state = True
|
||||
self.char_on.set_value(value, should_callback=False)
|
||||
service = SERVICE_TURN_ON if value else SERVICE_TURN_OFF
|
||||
self._hass.services.call(self._domain, service,
|
||||
{ATTR_ENTITY_ID: self._entity_id})
|
||||
|
|
|
@ -97,6 +97,7 @@ class Thermostat(HomeAccessory):
|
|||
|
||||
def set_heat_cool(self, value):
|
||||
"""Move operation mode to value if call came from HomeKit."""
|
||||
self.char_target_heat_cool.set_value(value, should_callback=False)
|
||||
if value in HC_HOMEKIT_TO_HASS:
|
||||
_LOGGER.debug('%s: Set heat-cool to %d', self._entity_id, value)
|
||||
self.heat_cool_flag_target_state = True
|
||||
|
@ -109,6 +110,7 @@ class Thermostat(HomeAccessory):
|
|||
_LOGGER.debug('%s: Set cooling threshold temperature to %.2f',
|
||||
self._entity_id, value)
|
||||
self.coolingthresh_flag_target_state = True
|
||||
self.char_cooling_thresh_temp.set_value(value, should_callback=False)
|
||||
low = self.char_heating_thresh_temp.value
|
||||
self._hass.components.climate.set_temperature(
|
||||
entity_id=self._entity_id, target_temp_high=value,
|
||||
|
@ -119,6 +121,7 @@ class Thermostat(HomeAccessory):
|
|||
_LOGGER.debug('%s: Set heating threshold temperature to %.2f',
|
||||
self._entity_id, value)
|
||||
self.heatingthresh_flag_target_state = True
|
||||
self.char_heating_thresh_temp.set_value(value, should_callback=False)
|
||||
# Home assistant always wants to set low and high at the same time
|
||||
high = self.char_cooling_thresh_temp.value
|
||||
self._hass.components.climate.set_temperature(
|
||||
|
@ -130,6 +133,7 @@ class Thermostat(HomeAccessory):
|
|||
_LOGGER.debug('%s: Set target temperature to %.2f',
|
||||
self._entity_id, value)
|
||||
self.temperature_flag_target_state = True
|
||||
self.char_target_temp.set_value(value, should_callback=False)
|
||||
self._hass.components.climate.set_temperature(
|
||||
temperature=value, entity_id=self._entity_id)
|
||||
|
||||
|
|
|
@ -16,17 +16,6 @@ _LOGGER = logging.getLogger(__name__)
|
|||
CONFIG = {}
|
||||
|
||||
|
||||
def test_get_accessory_invalid(caplog):
|
||||
"""Test with unsupported component."""
|
||||
assert get_accessory(None, State('test.unsupported', 'on'), 2, None) \
|
||||
is None
|
||||
assert caplog.records[1].levelname == 'WARNING'
|
||||
|
||||
assert get_accessory(None, State('test.test', 'on'), None, None) \
|
||||
is None
|
||||
assert caplog.records[3].levelname == 'WARNING'
|
||||
|
||||
|
||||
class TestGetAccessories(unittest.TestCase):
|
||||
"""Methods to test the get_accessory method."""
|
||||
|
||||
|
|
Loading…
Reference in New Issue