Advertisement
t30

3 test | tests/components/rollershutter/test_command_rollers

t30
Feb 13th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.44 KB | None | 0 0
  1.     def test_state_attributes_current_position(self):
  2.         self.assertTrue(rollershutter.setup(self.hass, {
  3.             'rollershutter': {
  4.                 'platform': 'command_rollershutter',
  5.                 'name': 'test',
  6.                 'upcmd': 'up-cmd',
  7.                 'downcmd': 'down-cmd',
  8.                 'stopcmd': 'stop-cmd',
  9.                 'statecmd': 'state-cmd'
  10.             }
  11.         }))
  12.  
  13.         state_attributes_dict = self.hass.states.get(
  14.             'rollershutter.test').attributes
  15.         self.assertFalse('current_position' in state_attributes_dict)
  16.  
  17.         # fire_mqtt_message(self.hass, 'state-topic', '0')
  18.         fire_state_changed(self.hass, 'state-cmd', '0')
  19.         self.hass.pool.block_till_done()
  20.         current_position = self.hass.states.get(
  21.             'rollershutter.test').attributes['current_position']
  22.         self.assertEqual(0, current_position)
  23.  
  24.         # fire_mqtt_message(self.hass, 'state-topic', '50')
  25.         fire_state_changed(self.hass, 'state-cmd', '50')
  26.         self.hass.pool.block_till_done()
  27.         current_position = self.hass.states.get(
  28.             'rollershutter.test').attributes['current_position']
  29.         self.assertEqual(50, current_position)
  30.  
  31.         # fire_mqtt_message(self.hass, 'state-topic', '101')
  32.         fire_state_changed(self.hass, 'state-cmd', '101')
  33.         self.hass.pool.block_till_done()
  34.         current_position = self.hass.states.get(
  35.             'rollershutter.test').attributes['current_position']
  36.         self.assertEqual(50, current_position)
  37.  
  38.         # fire_mqtt_message(self.hass, 'state-topic', 'non-numeric')
  39.         fire_state_changed(self.hass, 'state-cmd', 'non-numeric')
  40.         self.hass.pool.block_till_done()
  41.         current_position = self.hass.states.get(
  42.             'rollershutter.test').attributes['current_position']
  43.         self.assertEqual(50, current_position)
  44.  
  45.     def test_state_value(self):
  46.         with tempfile.TemporaryDirectory() as tempdirname:
  47.             path = os.path.join(tempdirname, 'rollershutter_status')
  48.             test_rollershutter = {
  49.                 'statecmd': 'cat {}'.format(path),
  50.                 'upcmd': 'echo 1 > {}'.format(path),
  51.                 'downcmd': 'echo 1 > {}'.format(path),
  52.                 'stopcmd': 'echo 0 > {}'.format(path),
  53.                 'value_template': '{{ value }}'
  54.             }
  55.             self.assertTrue(rollershutter.setup(self.hass, {
  56.                 'rollershutter': {
  57.                     'platform': 'command_rollershutter',
  58.                     'rollershutters': {
  59.                         'test': test_rollershutter
  60.                     }
  61.                 }
  62.             }))
  63.  
  64.             state = self.hass.states.get('rollershutter.test')
  65.             self.assertEqual('closed', state.state)
  66.  
  67.             rollershutter.move_up(self.hass, 'rollershutter.test')
  68.             self.hass.pool.block_till_done()
  69.  
  70.             state = self.hass.states.get('rollershutter.test')
  71.             self.assertEqual('open', state.state)
  72.  
  73.             rollershutter.move_down(self.hass, 'rollershutter.test')
  74.             self.hass.pool.block_till_done()
  75.  
  76.             state = self.hass.states.get('rollershutter.test')
  77.             self.assertEqual('open', state.state)
  78.  
  79.             rollershutter.stop(self.hass, 'rollershutter.test')
  80.             self.hass.pool.block_till_done()
  81.  
  82.             state = self.hass.states.get('rollershutter.test')
  83.             self.assertEqual('closed', state.state)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement