def test_calculation(self): """Test the mold indicator internal calculations.""" self.assertTrue( sensor.setup( self.hass, { 'sensor': { 'platform': 'mold_indicator', 'indoor_temp_sensor': 'test.indoortemp', 'outdoor_temp_sensor': 'test.outdoortemp', 'indoor_humidity_sensor': 'test.indoorhumidity', 'calibration_factor': '2.0' } })) moldind = self.hass.states.get('sensor.mold_indicator') assert moldind # assert dewpoint dewpoint = moldind.attributes.get(ATTR_DEWPOINT) assert dewpoint assert dewpoint > 9.25 assert dewpoint < 9.26 # assert temperature estimation esttemp = moldind.attributes.get(ATTR_CRITICAL_TEMP) assert esttemp assert esttemp > 14.9 assert esttemp < 15.1 # assert mold indicator value state = moldind.state assert state assert state == '68'
def test_sensor_changed(self): """Test the sensor_changed function.""" self.assertTrue(sensor.setup(self.hass, { 'sensor': { 'platform': 'mold_indicator', 'indoor_temp_sensor': 'test.indoortemp', 'outdoor_temp_sensor': 'test.outdoortemp', 'indoor_humidity_sensor': 'test.indoorhumidity', 'calibration_factor': '2.0' } })) # Change indoor temp self.hass.states.set('test.indoortemp', '30', {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}) self.hass.pool.block_till_done() assert self.hass.states.get('sensor.mold_indicator').state == '90' # Change outdoor temp self.hass.states.set('test.outdoortemp', '25', {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}) self.hass.pool.block_till_done() assert self.hass.states.get('sensor.mold_indicator').state == '57' # Change humidity self.hass.states.set('test.indoorhumidity', '20', {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}) self.hass.pool.block_till_done() assert self.hass.states.get('sensor.mold_indicator').state == '23'
def test_sensor_changed(self): """Test the sensor_changed function.""" self.assertTrue( sensor.setup( self.hass, { 'sensor': { 'platform': 'mold_indicator', 'indoor_temp_sensor': 'test.indoortemp', 'outdoor_temp_sensor': 'test.outdoortemp', 'indoor_humidity_sensor': 'test.indoorhumidity', 'calibration_factor': '2.0' } })) # Change indoor temp self.hass.states.set('test.indoortemp', '30', {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}) self.hass.pool.block_till_done() assert self.hass.states.get('sensor.mold_indicator').state == '90' # Change outdoor temp self.hass.states.set('test.outdoortemp', '25', {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}) self.hass.pool.block_till_done() assert self.hass.states.get('sensor.mold_indicator').state == '57' # Change humidity self.hass.states.set('test.indoorhumidity', '20', {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}) self.hass.pool.block_till_done() assert self.hass.states.get('sensor.mold_indicator').state == '23'
def test_calculation(self): """Test the mold indicator internal calculations.""" self.assertTrue(sensor.setup(self.hass, { 'sensor': { 'platform': 'mold_indicator', 'indoor_temp_sensor': 'test.indoortemp', 'outdoor_temp_sensor': 'test.outdoortemp', 'indoor_humidity_sensor': 'test.indoorhumidity', 'calibration_factor': '2.0' } })) moldind = self.hass.states.get('sensor.mold_indicator') assert moldind # assert dewpoint dewpoint = moldind.attributes.get(ATTR_DEWPOINT) assert dewpoint assert dewpoint > 9.25 assert dewpoint < 9.26 # assert temperature estimation esttemp = moldind.attributes.get(ATTR_CRITICAL_TEMP) assert esttemp assert esttemp > 14.9 assert esttemp < 15.1 # assert mold indicator value state = moldind.state assert state assert state == '68'
def test_invalidhum(self): """Test invalid sensor values.""" self.hass.states.set('test.indoortemp', '10', {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}) self.hass.states.set('test.outdoortemp', '10', {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}) self.hass.states.set('test.indoorhumidity', '0', {ATTR_UNIT_OF_MEASUREMENT: '%'}) self.assertTrue( sensor.setup( self.hass, { 'sensor': { 'platform': 'mold_indicator', 'indoor_temp_sensor': 'test.indoortemp', 'outdoor_temp_sensor': 'test.outdoortemp', 'indoor_humidity_sensor': 'test.indoorhumidity', 'calibration_factor': '2.0' } })) moldind = self.hass.states.get('sensor.mold_indicator') assert moldind # assert state assert moldind.state == '0'
def test_no_sensors_does_not_create(self): """Test no sensors.""" assert sensor.setup(self.hass, { 'sensor': { 'platform': 'template' } }) assert self.hass.states.all() == []
def test_invalid_sensor_does_not_create(self): """Test invalid sensor.""" assert sensor.setup(self.hass, { 'sensor': { 'platform': 'template', 'sensors': { 'test_template_sensor': 'invalid' } } }) assert self.hass.states.all() == []
def test_invalid_sensor_does_not_create(self): """Test invalid sensor.""" assert sensor.setup( self.hass, { 'sensor': { 'platform': 'template', 'sensors': { 'test_template_sensor': 'invalid' } } }) assert self.hass.states.all() == []
def test_setup_adds_proper_devices(self, mock_sensor, mock_client): """Test if setup adds devices.""" ports = {i: mock.MagicMock(model=model) for i, model in enumerate(mfi.SENSOR_MODELS)} ports['bad'] = mock.MagicMock(model='notasensor') print(ports['bad'].model) mock_client.return_value.get_devices.return_value = \ [mock.MagicMock(ports=ports)] assert sensor.setup(self.hass, self.GOOD_CONFIG) for ident, port in ports.items(): if ident != 'bad': mock_sensor.assert_any_call(port, self.hass) assert mock.call(ports['bad'], self.hass) not in mock_sensor.mock_calls
def test_invalid_name_does_not_create(self): """Test invalid name.""" assert sensor.setup(self.hass, { 'sensor': { 'platform': 'template', 'sensors': { 'test INVALID sensor': { 'value_template': "{{ states.sensor.test_state.state }}" } } } }) assert self.hass.states.all() == []
def test_missing_template_does_not_create(self): """Test missing template.""" assert sensor.setup(self.hass, { 'sensor': { 'platform': 'template', 'sensors': { 'test_template_sensor': { 'not_value_template': "{{ states.sensor.test_state.state }}" } } } }) assert self.hass.states.all() == []
def test_missing_template_does_not_create(self): """Test missing template.""" assert sensor.setup( self.hass, { 'sensor': { 'platform': 'template', 'sensors': { 'test_template_sensor': { 'not_value_template': "{{ states.sensor.test_state.state }}" } } } }) assert self.hass.states.all() == []
def test_setup(self): """Test the mold indicator sensor setup.""" self.assertTrue(sensor.setup(self.hass, { 'sensor': { 'platform': 'mold_indicator', 'indoor_temp_sensor': 'test.indoortemp', 'outdoor_temp_sensor': 'test.outdoortemp', 'indoor_humidity_sensor': 'test.indoorhumidity', 'calibration_factor': '2.0' } })) moldind = self.hass.states.get('sensor.mold_indicator') assert moldind assert '%' == moldind.attributes.get('unit_of_measurement')
def test_invalid_name_does_not_create(self): """Test invalid name.""" assert sensor.setup( self.hass, { 'sensor': { 'platform': 'template', 'sensors': { 'test INVALID sensor': { 'value_template': "{{ states.sensor.test_state.state }}" } } } }) assert self.hass.states.all() == []
def test_template_attribute_missing(self): """Test missing attribute template.""" assert sensor.setup(self.hass, { 'sensor': { 'platform': 'template', 'sensors': { 'test_template_sensor': { 'value_template': "It {{ states.sensor.test_state.attributes.missing }}." } } } }) state = self.hass.states.get('sensor.test_template_sensor') assert state.state == 'unknown'
def test_setup(self): """Test the mold indicator sensor setup.""" self.assertTrue( sensor.setup( self.hass, { 'sensor': { 'platform': 'mold_indicator', 'indoor_temp_sensor': 'test.indoortemp', 'outdoor_temp_sensor': 'test.outdoortemp', 'indoor_humidity_sensor': 'test.indoorhumidity', 'calibration_factor': '2.0' } })) moldind = self.hass.states.get('sensor.mold_indicator') assert moldind assert '%' == moldind.attributes.get('unit_of_measurement')
def test_template_attribute_missing(self): """Test missing attribute template.""" assert sensor.setup( self.hass, { 'sensor': { 'platform': 'template', 'sensors': { 'test_template_sensor': { 'value_template': "It {{ states.sensor.test_state.attributes.missing }}." } } } }) state = self.hass.states.get('sensor.test_template_sensor') assert state.state == 'unknown'
def test_template_syntax_error(self): """Test templating syntax error.""" assert sensor.setup(self.hass, { 'sensor': { 'platform': 'template', 'sensors': { 'test_template_sensor': { 'value_template': "{% if rubbish %}" } } } }) self.hass.states.set('sensor.test_state', 'Works') self.hass.pool.block_till_done() state = self.hass.states.get('sensor.test_template_sensor') assert state.state == 'unknown'
def test_template_syntax_error(self): """Test templating syntax error.""" assert sensor.setup( self.hass, { 'sensor': { 'platform': 'template', 'sensors': { 'test_template_sensor': { 'value_template': "{% if rubbish %}" } } } }) self.hass.states.set('sensor.test_state', 'Works') self.hass.pool.block_till_done() state = self.hass.states.get('sensor.test_template_sensor') assert state.state == 'unknown'
def test_template(self): """Test template.""" assert sensor.setup(self.hass, { 'sensor': { 'platform': 'template', 'sensors': { 'test_template_sensor': { 'value_template': "It {{ states.sensor.test_state.state }}." } } } }) state = self.hass.states.get('sensor.test_template_sensor') assert state.state == 'It .' self.hass.states.set('sensor.test_state', 'Works') self.hass.pool.block_till_done() state = self.hass.states.get('sensor.test_template_sensor') assert state.state == 'It Works.'
def test_template(self): """Test template.""" assert sensor.setup( self.hass, { 'sensor': { 'platform': 'template', 'sensors': { 'test_template_sensor': { 'value_template': "It {{ states.sensor.test_state.state }}." } } } }) state = self.hass.states.get('sensor.test_template_sensor') assert state.state == 'It .' self.hass.states.set('sensor.test_state', 'Works') self.hass.pool.block_till_done() state = self.hass.states.get('sensor.test_template_sensor') assert state.state == 'It Works.'
def test_invalidhum(self): """Test invalid sensor values.""" self.hass.states.set('test.indoortemp', '10', {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}) self.hass.states.set('test.outdoortemp', '10', {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}) self.hass.states.set('test.indoorhumidity', '0', {ATTR_UNIT_OF_MEASUREMENT: '%'}) self.assertTrue(sensor.setup(self.hass, { 'sensor': { 'platform': 'mold_indicator', 'indoor_temp_sensor': 'test.indoortemp', 'outdoor_temp_sensor': 'test.outdoortemp', 'indoor_humidity_sensor': 'test.indoorhumidity', 'calibration_factor': '2.0' } })) moldind = self.hass.states.get('sensor.mold_indicator') assert moldind # assert state assert moldind.state == '0'
def test_no_sensors_does_not_create(self): """Test no sensors.""" assert sensor.setup(self.hass, {'sensor': {'platform': 'template'}}) assert self.hass.states.all() == []