Skip to content

Commit

Permalink
Fix code after blueprint merging
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed Nov 6, 2023
1 parent 034d0c9 commit 2bada26
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions custom_components/snowtire/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from homeassistant.helpers.event import async_track_state_change
from homeassistant.helpers.typing import ConfigType
from homeassistant.util import dt as dt_util
from homeassistant.util.temperature import convert as convert_temperature
from homeassistant.util.unit_conversion import TemperatureConverter

from .const import (
CONF_DAYS,
Expand Down Expand Up @@ -144,7 +144,7 @@ def _temp2c(
) -> Optional[float]:
"""Convert weather temperature to Celsius degree."""
if temperature is not None and temperature_unit != TEMP_CELSIUS:
temperature = convert_temperature(
temperature = TemperatureConverter.convert(
temperature, temperature_unit, TEMP_CELSIUS
)

Expand Down
18 changes: 9 additions & 9 deletions custom_components/snowtire/manifest.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"domain": "snowtire",
"name": "Snowtire Sensor",
"version": "1.4.6-alpha",
"documentation": "https://github.com/Limych/ha-snowtire",
"issue_tracker": "https://github.com/Limych/ha-snowtire/issues",
"dependencies": [
"weather"
],
"config_flow": false,
"codeowners": [
"@limych"
],
"config_flow": false,
"dependencies": [
"weather"
],
"documentation": "https://github.com/Limych/ha-snowtire",
"iot_class": "calculated",
"issue_tracker": "https://github.com/Limych/ha-snowtire/issues",
"requirements": [],
"iot_class": "calculated"
}
"version": "1.4.6-alpha"
}
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pylint-strict-informational==0.1
pytest>=7.2
pytest-cov>=3.0
pytest-homeassistant-custom-component>=0.12
tzdata
14 changes: 9 additions & 5 deletions tests/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
ATTR_WEATHER_TEMPERATURE,
)
from homeassistant.const import CONF_PLATFORM, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, State
from homeassistant.exceptions import HomeAssistantError
from homeassistant.util import dt as dt_util

Expand Down Expand Up @@ -82,16 +82,20 @@ async def test_async_added_to_hass(default_sensor):


# pylint: disable=protected-access
async def test__temp2c():
@pytest.mark.parametrize(
"temp1, temp2",
[(0, -17.78), (10, -12.22), (20, -6.67), (30, -1.11), (40, 4.44), (50, 10)],
)
async def test__temp2c(temp1, temp2):
"""Test temperature conversions."""
assert SnowtireBinarySensor._temp2c(10, TEMP_CELSIUS) == 10
assert round(SnowtireBinarySensor._temp2c(10, TEMP_FAHRENHEIT), 2) == -12.22
assert SnowtireBinarySensor._temp2c(temp1, TEMP_CELSIUS) == temp1
assert round(SnowtireBinarySensor._temp2c(temp1, TEMP_FAHRENHEIT), 2) == temp2
assert SnowtireBinarySensor._temp2c(None, TEMP_CELSIUS) is None


async def test_async_update(hass: HomeAssistant, default_sensor):
"""Test sensor update."""
hass.states._states[MOCK_WEATHER_ENTITY] = None
hass.states._states[MOCK_WEATHER_ENTITY] = State(MOCK_WEATHER_ENTITY, None)

with raises(HomeAssistantError):
await default_sensor.async_update()
Expand Down

0 comments on commit 2bada26

Please sign in to comment.