'Test with state code.'

def test_state_code(self):

    with tempfile.TemporaryDirectory() as tempdirname:
        path = os.path.join(tempdirname, 'switch_status')
        test_switch = {'command_state': 'cat    {}'.format(path), 'command_on': 'echo    1    >    {}'.format(path), 'command_off': 'echo    0    >    {}'.format(path)}
        self.assertTrue(setup_component(self.hass, switch.DOMAIN, {'switch': {'platform': 'command_line', 'switches': {'test': test_switch}}}))
        state = self.hass.states.get('switch.test')
        self.assertEqual(STATE_OFF, state.state)
        switch.turn_on(self.hass, 'switch.test')
        self.hass.block_till_done()
        state = self.hass.states.get('switch.test')
        self.assertEqual(STATE_ON, state.state)
        switch.turn_off(self.hass, 'switch.test')
        self.hass.block_till_done()
        state = self.hass.states.get('switch.test')
        self.assertEqual(STATE_ON, state.state)
