async def test_switch_get_state(hass, init_integration): """Test states of the switch.""" init_integration registry = er.async_get(hass) entity_id = "switch.irrigation_switch" state = hass.states.get(entity_id) assert state assert state.state == STATE_OFF assert state.attributes.get("friendly_name") == "Irrigation switch" entry = registry.async_get(entity_id) assert entry assert entry.unique_id == uid states_response = get_states_response_for_uid(uid) states_response[0]["state"]["on"] = True with patch( "homeassistant.components.freedompro.get_states", return_value=states_response, ): async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() state = hass.states.get(entity_id) assert state assert state.attributes.get("friendly_name") == "Irrigation switch" entry = registry.async_get(entity_id) assert entry assert entry.unique_id == uid assert state.state == STATE_ON
async def test_lock_set_unlock(hass, init_integration): """Test set on of the lock.""" init_integration registry = er.async_get(hass) entity_id = "lock.lock" states_response = get_states_response_for_uid(uid) states_response[0]["state"]["lock"] = 1 with patch( "homeassistant.components.freedompro.get_states", return_value=states_response, ): await async_update_entity(hass, entity_id) async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() state = hass.states.get(entity_id) assert state assert state.state == STATE_LOCKED assert state.attributes.get("friendly_name") == "lock" entry = registry.async_get(entity_id) assert entry assert entry.unique_id == uid with patch("homeassistant.components.freedompro.lock.put_state" ) as mock_put_state: assert await hass.services.async_call( LOCK_DOMAIN, SERVICE_UNLOCK, {ATTR_ENTITY_ID: [entity_id]}, blocking=True, ) mock_put_state.assert_called_once_with(ANY, ANY, ANY, '{"lock": 0}') states_response = get_states_response_for_uid(uid) states_response[0]["state"]["lock"] = 0 with patch( "homeassistant.components.freedompro.get_states", return_value=states_response, ): async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() state = hass.states.get(entity_id) assert state.state == STATE_UNLOCKED
async def test_switch_set_off(hass, init_integration): """Test set off of the switch.""" init_integration registry = er.async_get(hass) entity_id = "switch.irrigation_switch" states_response = get_states_response_for_uid(uid) states_response[0]["state"]["on"] = True with patch( "homeassistant.components.freedompro.get_states", return_value=states_response, ): await async_update_entity(hass, entity_id) async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() state = hass.states.get(entity_id) assert state assert state.state == STATE_ON assert state.attributes.get("friendly_name") == "Irrigation switch" entry = registry.async_get(entity_id) assert entry assert entry.unique_id == uid with patch("homeassistant.components.freedompro.switch.put_state" ) as mock_put_state: assert await hass.services.async_call( SWITCH_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: [entity_id]}, blocking=True, ) mock_put_state.assert_called_once_with(ANY, ANY, ANY, '{"on": false}') states_response = get_states_response_for_uid(uid) states_response[0]["state"]["on"] = False with patch( "homeassistant.components.freedompro.get_states", return_value=states_response, ): async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() state = hass.states.get(entity_id) assert state.state == STATE_OFF
async def test_climate_get_state(hass, init_integration): """Test states of the climate.""" entity_registry = er.async_get(hass) device_registry = dr.async_get(hass) device = device_registry.async_get_device({("freedompro", uid)}) assert device is not None assert device.identifiers == {("freedompro", uid)} assert device.manufacturer == "Freedompro" assert device.name == "thermostat" assert device.model == "thermostat" entity_id = "climate.thermostat" state = hass.states.get(entity_id) assert state assert state.attributes.get("friendly_name") == "thermostat" assert state.attributes[ATTR_HVAC_MODES] == [ HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_COOL, ] assert state.attributes[ATTR_MIN_TEMP] == 7 assert state.attributes[ATTR_MAX_TEMP] == 35 assert state.attributes[ATTR_TEMPERATURE] == 14 assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 14 assert state.state == HVAC_MODE_HEAT entry = entity_registry.async_get(entity_id) assert entry assert entry.unique_id == uid states_response = get_states_response_for_uid(uid) states_response[0]["state"]["currentTemperature"] = 20 states_response[0]["state"]["targetTemperature"] = 21 with patch( "homeassistant.components.freedompro.get_states", return_value=states_response, ): async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() state = hass.states.get(entity_id) assert state assert state.attributes.get("friendly_name") == "thermostat" entry = entity_registry.async_get(entity_id) assert entry assert entry.unique_id == uid assert state.attributes[ATTR_TEMPERATURE] == 21 assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 20
async def test_fan_set_off(hass, init_integration): """Test turn off the fan.""" init_integration registry = er.async_get(hass) entity_id = "fan.bedroom" states_response = get_states_response_for_uid(uid) states_response[0]["state"]["on"] = True states_response[0]["state"]["rotationSpeed"] = 50 with patch( "homeassistant.components.freedompro.get_states", return_value=states_response, ): await hass.helpers.entity_component.async_update_entity(entity_id) async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() state = hass.states.get(entity_id) assert state assert state.state == STATE_ON assert state.attributes[ATTR_PERCENTAGE] == 50 assert state.attributes.get("friendly_name") == "bedroom" entry = registry.async_get(entity_id) assert entry assert entry.unique_id == uid with patch("homeassistant.components.freedompro.fan.put_state" ) as mock_put_state: assert await hass.services.async_call( FAN_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: [entity_id]}, blocking=True, ) mock_put_state.assert_called_once_with(ANY, ANY, ANY, '{"on": false}') states_response[0]["state"]["on"] = False states_response[0]["state"]["rotationSpeed"] = 0 with patch( "homeassistant.components.freedompro.get_states", return_value=states_response, ): await hass.helpers.entity_component.async_update_entity(entity_id) async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() await hass.async_block_till_done() state = hass.states.get(entity_id) assert state.attributes[ATTR_PERCENTAGE] == 0 assert state.state == STATE_OFF
async def test_cover_close(hass, init_integration, entity_id: str, uid: str, name: str, model: str): """Test close cover.""" init_integration registry = er.async_get(hass) states_response = get_states_response_for_uid(uid) states_response[0]["state"]["position"] = 100 with patch( "homeassistant.components.freedompro.get_states", return_value=states_response, ): await async_update_entity(hass, entity_id) async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() state = hass.states.get(entity_id) assert state assert state.state == STATE_OPEN assert state.attributes.get("friendly_name") == name entry = registry.async_get(entity_id) assert entry assert entry.unique_id == uid with patch("homeassistant.components.freedompro.cover.put_state" ) as mock_put_state: assert await hass.services.async_call( COVER_DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: [entity_id]}, blocking=True, ) mock_put_state.assert_called_once_with(ANY, ANY, ANY, '{"position": 0}') states_response[0]["state"]["position"] = 0 with patch( "homeassistant.components.freedompro.get_states", return_value=states_response, ): async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() state = hass.states.get(entity_id) assert state.state == STATE_CLOSED
async def test_fan_get_state(hass, init_integration): """Test states of the fan.""" init_integration registry = er.async_get(hass) registry_device = dr.async_get(hass) device = registry_device.async_get_device({("freedompro", uid)}) assert device is not None assert device.identifiers == {("freedompro", uid)} assert device.manufacturer == "Freedompro" assert device.name == "bedroom" assert device.model == "fan" entity_id = "fan.bedroom" state = hass.states.get(entity_id) assert state assert state.state == STATE_OFF assert state.attributes[ATTR_PERCENTAGE] == 0 assert state.attributes.get("friendly_name") == "bedroom" entry = registry.async_get(entity_id) assert entry assert entry.unique_id == uid states_response = get_states_response_for_uid(uid) states_response[0]["state"]["on"] = True states_response[0]["state"]["rotationSpeed"] = 50 with patch( "homeassistant.components.freedompro.get_states", return_value=states_response, ): async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() state = hass.states.get(entity_id) assert state assert state.attributes.get("friendly_name") == "bedroom" entry = registry.async_get(entity_id) assert entry assert entry.unique_id == uid assert state.state == STATE_ON assert state.attributes[ATTR_PERCENTAGE] == 50
async def test_climate_set_temperature(hass, init_integration): """Test set temperature climate.""" init_integration entity_registry = er.async_get(hass) entity_id = "climate.thermostat" state = hass.states.get(entity_id) assert state assert state.attributes.get("friendly_name") == "thermostat" entry = entity_registry.async_get(entity_id) assert entry assert entry.unique_id == uid with patch( "homeassistant.components.freedompro.climate.put_state" ) as mock_put_state: assert await hass.services.async_call( CLIMATE_DOMAIN, SERVICE_SET_TEMPERATURE, { ATTR_ENTITY_ID: [entity_id], ATTR_HVAC_MODE: HVACMode.OFF, ATTR_TEMPERATURE: 25, }, blocking=True, ) mock_put_state.assert_called_once_with( ANY, ANY, ANY, '{"heatingCoolingState": 0, "targetTemperature": 25.0}' ) states_response = get_states_response_for_uid(uid) states_response[0]["state"]["currentTemperature"] = 20 states_response[0]["state"]["targetTemperature"] = 21 with patch( "homeassistant.components.freedompro.get_states", return_value=states_response, ): async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() state = hass.states.get(entity_id) assert state.attributes[ATTR_TEMPERATURE] == 21
async def test_cover_get_state(hass, init_integration, entity_id: str, uid: str, name: str, model: str): """Test states of the cover.""" init_integration registry = er.async_get(hass) registry_device = dr.async_get(hass) device = registry_device.async_get_device({("freedompro", uid)}) assert device is not None assert device.identifiers == {("freedompro", uid)} assert device.manufacturer == "Freedompro" assert device.name == name assert device.model == model state = hass.states.get(entity_id) assert state assert state.state == STATE_CLOSED assert state.attributes.get("friendly_name") == name entry = registry.async_get(entity_id) assert entry assert entry.unique_id == uid states_response = get_states_response_for_uid(uid) states_response[0]["state"]["position"] = 100 with patch( "homeassistant.components.freedompro.get_states", return_value=states_response, ): async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() state = hass.states.get(entity_id) assert state assert state.attributes.get("friendly_name") == name entry = registry.async_get(entity_id) assert entry assert entry.unique_id == uid assert state.state == STATE_OPEN
async def test_sensor_get_state(hass, init_integration, entity_id: str, uid: str, name: str): """Test states of the sensor.""" init_integration registry = er.async_get(hass) state = hass.states.get(entity_id) assert state assert state.attributes.get("friendly_name") == name entry = registry.async_get(entity_id) assert entry assert entry.unique_id == uid assert state.state == "0" states_response = get_states_response_for_uid(uid) if states_response[0]["type"] == "lightSensor": states_response[0]["state"]["currentAmbientLightLevel"] = "1" elif states_response[0]["type"] == "temperatureSensor": states_response[0]["state"]["currentTemperature"] = "1" elif states_response[0]["type"] == "humiditySensor": states_response[0]["state"]["currentRelativeHumidity"] = "1" with patch( "homeassistant.components.freedompro.get_states", return_value=states_response, ): async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() state = hass.states.get(entity_id) assert state assert state.attributes.get("friendly_name") == name entry = registry.async_get(entity_id) assert entry assert entry.unique_id == uid assert state.state == "1"
async def test_binary_sensor_get_state(hass, init_integration, entity_id: str, uid: str, name: str, model: str): """Test states of the binary_sensor.""" init_integration registry = er.async_get(hass) registry_device = dr.async_get(hass) device = registry_device.async_get_device({("freedompro", uid)}) assert device is not None assert device.identifiers == {("freedompro", uid)} assert device.manufacturer == "Freedompro" assert device.name == name assert device.model == model state = hass.states.get(entity_id) assert state assert state.attributes.get("friendly_name") == name entry = registry.async_get(entity_id) assert entry assert entry.unique_id == uid assert state.state == STATE_OFF with patch( "homeassistant.components.freedompro.get_states", return_value=[], ): async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() state = hass.states.get(entity_id) assert state assert state.attributes.get("friendly_name") == name entry = registry.async_get(entity_id) assert entry assert entry.unique_id == uid assert state.state == STATE_OFF states_response = get_states_response_for_uid(uid) if states_response[0]["type"] == "smokeSensor": states_response[0]["state"]["smokeDetected"] = True elif states_response[0]["type"] == "occupancySensor": states_response[0]["state"]["occupancyDetected"] = True elif states_response[0]["type"] == "motionSensor": states_response[0]["state"]["motionDetected"] = True elif states_response[0]["type"] == "contactSensor": states_response[0]["state"]["contactSensorState"] = True with patch( "homeassistant.components.freedompro.get_states", return_value=states_response, ): async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() state = hass.states.get(entity_id) assert state assert state.attributes.get("friendly_name") == name entry = registry.async_get(entity_id) assert entry assert entry.unique_id == uid assert state.state == STATE_ON