def test_temperature_not_a_number(hass):
    """Test that temperature is a number."""
    temp = "Temperature"
    with pytest.raises(Exception) as exception:
        display_temp(hass, temp, TEMP_CELSIUS, PRECISION_HALVES)

    assert f"Temperature is not a number: {temp}" in str(exception.value)
    def test_temperature_not_a_number(self):
        """Test that temperature is a number."""
        temp = "Temperature"
        with pytest.raises(Exception) as exception:
            display_temp(self.hass, temp, TEMP_CELSIUS, PRECISION_HALVES)

        assert "Temperature is not a number: {}".format(temp) \
            in str(exception)
    def test_temperature_not_a_number(self):
        """Test that temperature is a number."""
        temp = "Temperature"
        with self.assertRaises(Exception) as context:
            display_temp(self.hass, temp, TEMP_CELSIUS, PRECISION_HALVES)

        self.assertTrue("Temperature is not a number: {}".format(temp)
                        in str(context.exception))
    def test_temperature_not_a_number(self):
        """Test that temperature is a number."""
        temp = "Temperature"
        with self.assertRaises(Exception) as context:
            display_temp(self.hass, temp, TEMP_CELSIUS, PRECISION_HALVES)

        self.assertTrue("Temperature is not a number: {}".format(temp) in str(
            context.exception))
    def test_temperature_not_a_number(self):
        """Test that temperature is a number."""
        temp = "Temperature"
        with pytest.raises(Exception) as exception:
            display_temp(self.hass, temp, TEMP_CELSIUS, PRECISION_HALVES)

        assert "Temperature is not a number: {}".format(temp) \
            in str(exception)
 def update(self):
     """Fetch temperature from the sensor."""
     super().update()
     temp_celsius = self._sensor.temperature
     if temp_celsius is not None:
         self._state = display_temp(self.hass, temp_celsius,
                                    TEMP_CELSIUS, PRECISION_TENTHS)
Beispiel #7
0
    def state(self) -> Any | None:
        """Return the state."""
        attr = getattr(self._api.storage, self.entity_type)(self._device_id)
        if attr is None:
            return None

        # Data (disk space)
        if self._unit == DATA_TERABYTES:
            return round(attr / 1024.0 ** 4, 2)

        # Temperature
        if self.entity_type in TEMP_SENSORS_KEYS:
            return display_temp(self.hass, attr, TEMP_CELSIUS, PRECISION_TENTHS)

        return attr
Beispiel #8
0
    def state(self) -> Any | None:
        """Return the state."""
        attr = getattr(self._api.information, self.entity_type)
        if attr is None:
            return None

        # Temperature
        if self.entity_type in TEMP_SENSORS_KEYS:
            return display_temp(self.hass, attr, TEMP_CELSIUS, PRECISION_TENTHS)

        if self.entity_type == "uptime":
            # reboot happened or entity creation
            if self._previous_uptime is None or self._previous_uptime > attr:
                last_boot = utcnow() - timedelta(seconds=attr)
                self._last_boot = last_boot.replace(microsecond=0).isoformat()

            self._previous_uptime = attr
            return self._last_boot
        return attr
Beispiel #9
0
    def state_attributes(self):
        """Return the optional state attributes."""
        data = {
            ATTR_CURRENT_TEMPERATURE:
            display_temp(self.hass, self.current_temperature,
                         self.temperature_unit, self.precision),
            ATTR_OPERATION_MODE:
            self.current_operation,
            ATTR_AWAY_MODE:
            STATE_ON if self.is_away_mode_on else STATE_OFF,
            ATTR_AVAILABLE_PERCENT:
            round(self._data["hw_avail_fraction"] * 100),
            ATTR_PERFORMANCE_MODE:
            self._data["efficiencySelection"],
            ATTR_AQUANTA_INTELLIGENCE_ACIVE:
            not self._settings["aquantaIntel"],
        }

        return data
 def test_celsius_halves(self):
     """Test temperature to celsius rounding to halves."""
     assert 24.5 == display_temp(
         self.hass, TEMP, TEMP_CELSIUS, PRECISION_HALVES)
def test_fahrenheit_wholes(hass):
    """Test temperature to fahrenheit rounding to wholes."""
    assert display_temp(hass, TEMP, TEMP_FAHRENHEIT, PRECISION_WHOLE) == -4
def test_celsius_halves(hass):
    """Test temperature to celsius rounding to halves."""
    assert display_temp(hass, TEMP, TEMP_CELSIUS, PRECISION_HALVES) == 24.5
Beispiel #13
0
 def test_fahrenheit_wholes(self):
     """Test temperature to fahrenheit rounding to wholes."""
     self.assertEqual(
         -4, display_temp(self.hass, TEMP, TEMP_FAHRENHEIT,
                          PRECISION_WHOLE))
Beispiel #14
0
 def test_celsius_tenths(self):
     """Test temperature to celsius rounding to tenths."""
     self.assertEqual(
         24.6, display_temp(self.hass, TEMP, TEMP_CELSIUS,
                            PRECISION_TENTHS))
Beispiel #15
0
 def test_celsius_halves(self):
     """Test temperature to celsius rounding to halves."""
     self.assertEqual(
         24.5, display_temp(self.hass, TEMP, TEMP_CELSIUS,
                            PRECISION_HALVES))
 def test_celsius_tenths(self):
     """Test temperature to celsius rounding to tenths."""
     assert 24.6 == display_temp(
         self.hass, TEMP, TEMP_CELSIUS, PRECISION_TENTHS)
 def test_fahrenheit_wholes(self):
     """Test temperature to fahrenheit rounding to wholes."""
     assert -4 == display_temp(
         self.hass, TEMP, TEMP_FAHRENHEIT, PRECISION_WHOLE)
def test_celsius_tenths(hass):
    """Test temperature to celsius rounding to tenths."""
    assert display_temp(hass, TEMP, TEMP_CELSIUS, PRECISION_TENTHS) == 24.6