<s> """<STR_LIT>""" <EOL> import unittest <EOL> import unittest . mock as mock <EOL> import homeassistant . components . switch as switch <EOL> import homeassistant . components . switch . mfi as mfi <EOL> from tests . components . sensor import test_mfi as test_mfi_sensor <EOL> from tests . common import get_test_home_assistant <EOL> class TestMfiSwitchSetup ( test_mfi_sensor . TestMfiSensorSetup ) : <EOL> """<STR_LIT>""" <EOL> PLATFORM = mfi <EOL> COMPONENT = switch <EOL> THING = '<STR_LIT>' <EOL> GOOD_CONFIG = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:host>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT:port>' : <NUM_LIT> , <EOL> '<STR_LIT:username>' : '<STR_LIT:user>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> } <EOL> } <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_setup_adds_proper_devices ( self , mock_switch , mock_client ) : <EOL> """<STR_LIT>""" <EOL> ports = { i : mock . MagicMock ( model = model ) <EOL> for i , model in enumerate ( mfi . SWITCH_MODELS ) } <EOL> ports [ '<STR_LIT>' ] = mock . MagicMock ( model = '<STR_LIT>' ) <EOL> print ( ports [ '<STR_LIT>' ] . model ) <EOL> mock_client . return_value . get_devices . return_value = [ mock . MagicMock ( ports = ports ) ] <EOL> assert self . COMPONENT . setup ( self . hass , self . GOOD_CONFIG ) <EOL> for ident , port in ports . items ( ) : <EOL> if ident != '<STR_LIT>' : <EOL> mock_switch . assert_any_call ( port ) <EOL> assert mock . call ( ports [ '<STR_LIT>' ] , self . hass ) not in mock_switch . mock_calls <EOL> class TestMfiSwitch ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setup_method ( self , method ) : <EOL> """<STR_LIT>""" <EOL> self . hass = get_test_home_assistant ( ) <EOL> self . hass . config . latitude = <NUM_LIT> <EOL> self . hass . config . longitude = <NUM_LIT> <EOL> self . port = mock . MagicMock ( ) <EOL> self . switch = mfi . MfiSwitch ( self . port ) <EOL> def teardown_method ( self , method ) : <EOL> """<STR_LIT>""" <EOL> self . hass . stop ( ) <EOL> def test_name ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . port . label , self . switch . name ) <EOL> def test_update ( self ) : <EOL> """<STR_LIT>""" <EOL> self . switch . update ( ) <EOL> self . port . refresh . assert_called_once_with ( ) <EOL> def test_update_with_target_state ( self ) : <EOL> """<STR_LIT>""" <EOL> self . switch . _target_state = True <EOL> self . port . data = { } <EOL> self . port . data [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . switch . update ( ) <EOL> self . assertEqual ( <NUM_LIT:1.0> , self . port . data [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( None , self . switch . _target_state ) <EOL> self . port . data [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . switch . update ( ) <EOL> self . assertEqual ( '<STR_LIT>' , self . port . data [ '<STR_LIT>' ] ) <EOL> def test_turn_on ( self ) : <EOL> """<STR_LIT>""" <EOL> self . switch . turn_on ( ) <EOL> self . port . control . assert_called_once_with ( True ) <EOL> self . assertTrue ( self . switch . _target_state ) <EOL> def test_turn_off ( self ) : <EOL> """<STR_LIT>""" <EOL> self . switch . turn_off ( ) <EOL> self . port . control . assert_called_once_with ( False ) <EOL> self . assertFalse ( self . switch . _target_state ) <EOL> def test_current_power_mwh ( self ) : <EOL> """<STR_LIT>""" <EOL> self . port . data = { '<STR_LIT>' : <NUM_LIT:1> } <EOL> self . assertEqual ( <NUM_LIT:1000> , self . switch . current_power_mwh ) <EOL> def test_current_power_mwh_no_data ( self ) : <EOL> """<STR_LIT>""" <EOL> self . port . data = { '<STR_LIT>' : <NUM_LIT> } <EOL> self . assertEqual ( <NUM_LIT:0> , self . switch . current_power_mwh ) <EOL> def test_device_state_attributes ( self ) : <EOL> """<STR_LIT>""" <EOL> self . port . data = { '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> } <EOL> self . assertEqual ( { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } , <EOL> self . switch . device_state_attributes ) </s>
