Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def test_state_attributes_current_position(self):
- self.assertTrue(rollershutter.setup(self.hass, {
- 'rollershutter': {
- 'platform': 'command_rollershutter',
- 'name': 'test',
- 'upcmd': 'up-cmd',
- 'downcmd': 'down-cmd',
- 'stopcmd': 'stop-cmd',
- 'statecmd': 'state-cmd'
- }
- }))
- state_attributes_dict = self.hass.states.get(
- 'rollershutter.test').attributes
- self.assertFalse('current_position' in state_attributes_dict)
- # fire_mqtt_message(self.hass, 'state-topic', '0')
- fire_state_changed(self.hass, 'state-cmd', '0')
- self.hass.pool.block_till_done()
- current_position = self.hass.states.get(
- 'rollershutter.test').attributes['current_position']
- self.assertEqual(0, current_position)
- # fire_mqtt_message(self.hass, 'state-topic', '50')
- fire_state_changed(self.hass, 'state-cmd', '50')
- self.hass.pool.block_till_done()
- current_position = self.hass.states.get(
- 'rollershutter.test').attributes['current_position']
- self.assertEqual(50, current_position)
- # fire_mqtt_message(self.hass, 'state-topic', '101')
- fire_state_changed(self.hass, 'state-cmd', '101')
- self.hass.pool.block_till_done()
- current_position = self.hass.states.get(
- 'rollershutter.test').attributes['current_position']
- self.assertEqual(50, current_position)
- # fire_mqtt_message(self.hass, 'state-topic', 'non-numeric')
- fire_state_changed(self.hass, 'state-cmd', 'non-numeric')
- self.hass.pool.block_till_done()
- current_position = self.hass.states.get(
- 'rollershutter.test').attributes['current_position']
- self.assertEqual(50, current_position)
- def test_state_value(self):
- with tempfile.TemporaryDirectory() as tempdirname:
- path = os.path.join(tempdirname, 'rollershutter_status')
- test_rollershutter = {
- 'statecmd': 'cat {}'.format(path),
- 'upcmd': 'echo 1 > {}'.format(path),
- 'downcmd': 'echo 1 > {}'.format(path),
- 'stopcmd': 'echo 0 > {}'.format(path),
- 'value_template': '{{ value }}'
- }
- self.assertTrue(rollershutter.setup(self.hass, {
- 'rollershutter': {
- 'platform': 'command_rollershutter',
- 'rollershutters': {
- 'test': test_rollershutter
- }
- }
- }))
- state = self.hass.states.get('rollershutter.test')
- self.assertEqual('closed', state.state)
- rollershutter.move_up(self.hass, 'rollershutter.test')
- self.hass.pool.block_till_done()
- state = self.hass.states.get('rollershutter.test')
- self.assertEqual('open', state.state)
- rollershutter.move_down(self.hass, 'rollershutter.test')
- self.hass.pool.block_till_done()
- state = self.hass.states.get('rollershutter.test')
- self.assertEqual('open', state.state)
- rollershutter.stop(self.hass, 'rollershutter.test')
- self.hass.pool.block_till_done()
- state = self.hass.states.get('rollershutter.test')
- self.assertEqual('closed', state.state)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement