async def test_humidity(hass, hk_driver): """Test if accessory is updated after state change.""" entity_id = "sensor.humidity" hass.states.async_set(entity_id, None) await hass.async_block_till_done() acc = HumiditySensor(hass, hk_driver, "Humidity", entity_id, 2, None) await acc.run() await hass.async_block_till_done() assert acc.aid == 2 assert acc.category == 10 # Sensor assert acc.char_humidity.value == 0 hass.states.async_set(entity_id, STATE_UNKNOWN) await hass.async_block_till_done() assert acc.char_humidity.value == 0 hass.states.async_set(entity_id, "20") await hass.async_block_till_done() assert acc.char_humidity.value == 20 hass.states.async_set(entity_id, "0") await hass.async_block_till_done() assert acc.char_humidity.value == 0
async def test_empty_name(hass, hk_driver): """Test an entity with a empty name.""" entity_id = "sensor.humidity" hass.states.async_set(entity_id, "20") await hass.async_block_till_done() acc = HumiditySensor(hass, hk_driver, None, entity_id, 2, None) await acc.run() await hass.async_block_till_done() assert acc.aid == 2 assert acc.category == 10 # Sensor assert acc.char_humidity.value == 20 assert acc.display_name is None
def test_humidity(self): """Test if accessory is updated after state change.""" entity_id = 'sensor.humidity' acc = HumiditySensor(self.hass, entity_id, 'Humidity', aid=2) acc.run() self.assertEqual(acc.aid, 2) self.assertEqual(acc.category, 10) # Sensor self.assertEqual(acc.char_humidity.value, 0) self.hass.states.set(entity_id, STATE_UNKNOWN, {ATTR_UNIT_OF_MEASUREMENT: "%"}) self.hass.block_till_done() self.hass.states.set(entity_id, '20', {ATTR_UNIT_OF_MEASUREMENT: "%"}) self.hass.block_till_done() self.assertEqual(acc.char_humidity.value, 20)
def test_humidity(self): """Test if accessory is updated after state change.""" entity_id = 'sensor.humidity' acc = HumiditySensor(self.hass, 'Humidity', entity_id, 2, config=None) acc.run() self.assertEqual(acc.aid, 2) self.assertEqual(acc.category, 10) # Sensor self.assertEqual(acc.char_humidity.value, 0) self.hass.states.set(entity_id, STATE_UNKNOWN) self.hass.block_till_done() self.assertEqual(acc.char_humidity.value, 0) self.hass.states.set(entity_id, '20') self.hass.block_till_done() self.assertEqual(acc.char_humidity.value, 20)
async def test_humidity(hass): """Test if accessory is updated after state change.""" entity_id = 'sensor.humidity' hass.states.async_set(entity_id, None) await hass.async_block_till_done() acc = HumiditySensor(hass, 'Humidity', entity_id, 2, None) await hass.async_add_job(acc.run) assert acc.aid == 2 assert acc.category == 10 # Sensor assert acc.char_humidity.value == 0 hass.states.async_set(entity_id, STATE_UNKNOWN) await hass.async_block_till_done() assert acc.char_humidity.value == 0 hass.states.async_set(entity_id, '20') await hass.async_block_till_done() assert acc.char_humidity.value == 20