Beispiel #1
0
    def aiohttp_client_update_ppm_overflow(self, mock_function):
        """Test MHZClient when ppm is too high."""
        from pmsensor import co2sensor

        client = mhz19.MHZClient(co2sensor, "test.serial")
        client.update()
        assert client.data.get("co2") is None
Beispiel #2
0
    def aiohttp_client_update_good_read(self, mock_function):
        """Test MHZClient when ppm is too high."""
        from pmsensor import co2sensor

        client = mhz19.MHZClient(co2sensor, "test.serial")
        client.update()
        assert {"temperature": 24, "co2": 1000} == client.data
Beispiel #3
0
    def aiohttp_client_update_oserror(self, mock_function):
        """Test MHZClient when library throws OSError."""
        from pmsensor import co2sensor

        client = mhz19.MHZClient(co2sensor, "test.serial")
        client.update()
        assert {} == client.data
Beispiel #4
0
async def test_temperature_sensor_f(mock_function):
    """Test temperature sensor."""
    client = mhz19.MHZClient(co2sensor, "test.serial")
    sensor = mhz19.MHZ19Sensor(client, mhz19.SENSOR_TEMPERATURE,
                               TEMP_FAHRENHEIT, "name")
    sensor.update()

    assert sensor.state == 75.2
async def test_temperature_sensor_f(mock_function, hass):
    """Test temperature sensor."""
    with patch.object(hass.config.units, "temperature_unit", TEMP_FAHRENHEIT):
        client = mhz19.MHZClient(co2sensor, "test.serial")
        sensor = mhz19.MHZ19Sensor(client, "name", mhz19.SENSOR_TYPES[0])
        sensor.hass = hass
        sensor.update()

        assert sensor.state == 75
Beispiel #6
0
    def test_temperature_sensor_f(self, mock_function):
        """Test temperature sensor."""
        from pmsensor import co2sensor

        client = mhz19.MHZClient(co2sensor, "test.serial")
        sensor = mhz19.MHZ19Sensor(client, mhz19.SENSOR_TEMPERATURE,
                                   TEMP_FAHRENHEIT, "name")
        sensor.update()

        assert 75.2 == sensor.state
Beispiel #7
0
async def test_temperature_sensor(mock_function):
    """Test temperature sensor."""
    client = mhz19.MHZClient(co2sensor, "test.serial")
    sensor = mhz19.MHZ19Sensor(client, mhz19.SENSOR_TEMPERATURE, None, "name")
    sensor.update()

    assert sensor.name == "name: Temperature"
    assert sensor.state == 24
    assert sensor.unit_of_measurement == TEMP_CELSIUS
    assert sensor.should_poll
    assert sensor.device_state_attributes == {"co2_concentration": 1000}
Beispiel #8
0
async def test_co2_sensor(mock_function):
    """Test CO2 sensor."""
    client = mhz19.MHZClient(co2sensor, "test.serial")
    sensor = mhz19.MHZ19Sensor(client, mhz19.SENSOR_CO2, None, "name")
    sensor.update()

    assert sensor.name == "name: CO2"
    assert sensor.state == 1000
    assert sensor.unit_of_measurement == CONCENTRATION_PARTS_PER_MILLION
    assert sensor.should_poll
    assert sensor.device_state_attributes == {"temperature": 24}
async def test_co2_sensor(mock_function, hass):
    """Test CO2 sensor."""
    client = mhz19.MHZClient(co2sensor, "test.serial")
    sensor = mhz19.MHZ19Sensor(client, "name", mhz19.SENSOR_TYPES[1])
    sensor.hass = hass
    sensor.update()

    assert sensor.name == "name: CO2"
    assert sensor.state == 1000
    assert sensor.native_unit_of_measurement == CONCENTRATION_PARTS_PER_MILLION
    assert sensor.should_poll
    assert sensor.extra_state_attributes == {"temperature": 24}
async def test_temperature_sensor(mock_function, hass):
    """Test temperature sensor."""
    client = mhz19.MHZClient(co2sensor, "test.serial")
    sensor = mhz19.MHZ19Sensor(client, "name", mhz19.SENSOR_TYPES[0])
    sensor.hass = hass
    sensor.update()

    assert sensor.name == "name: Temperature"
    assert sensor.state == 24
    assert sensor.native_unit_of_measurement == TEMP_CELSIUS
    assert sensor.should_poll
    assert sensor.extra_state_attributes == {"co2_concentration": 1000}
Beispiel #11
0
    def test_co2_sensor(self, mock_function):
        """Test CO2 sensor."""
        from pmsensor import co2sensor

        client = mhz19.MHZClient(co2sensor, "test.serial")
        sensor = mhz19.MHZ19Sensor(client, mhz19.SENSOR_CO2, None, "name")
        sensor.update()

        assert "name: CO2" == sensor.name
        assert 1000 == sensor.state
        assert "ppm" == sensor.unit_of_measurement
        assert sensor.should_poll
        assert {"temperature": 24} == sensor.device_state_attributes
Beispiel #12
0
    def test_temperature_sensor(self, mock_function):
        """Test temperature sensor."""
        from pmsensor import co2sensor

        client = mhz19.MHZClient(co2sensor, "test.serial")
        sensor = mhz19.MHZ19Sensor(client, mhz19.SENSOR_TEMPERATURE, None,
                                   "name")
        sensor.update()

        assert "name: Temperature" == sensor.name
        assert 24 == sensor.state
        assert "°C" == sensor.unit_of_measurement
        assert sensor.should_poll
        assert {"co2_concentration": 1000} == sensor.device_state_attributes
Beispiel #13
0
async def aiohttp_client_update_oserror(mock_function):
    """Test MHZClient when library throws OSError."""
    client = mhz19.MHZClient(co2sensor, "test.serial")
    client.update()
    assert {} == client.data