Skip to content

Commit

Permalink
fix deprecated constants TEMP_CELSIUS and TIME_MINUTES (#300)
Browse files Browse the repository at this point in the history
* fix deprecated constants TEMP_CELSIUS and TIME_MINUTES

* Fix test dep

* Fix tests

---------

Co-authored-by: Olivér Falvai <[email protected]>
  • Loading branch information
bodny and ofalvai authored Jan 5, 2025
1 parent bba68e9 commit fed64a7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
13 changes: 8 additions & 5 deletions custom_components/candy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

from homeassistant.components.sensor import SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS, TIME_MINUTES
from homeassistant.const import (
UnitOfTime,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.typing import StateType
Expand Down Expand Up @@ -171,7 +174,7 @@ def state(self) -> StateType:

@property
def unit_of_measurement(self) -> str:
return TIME_MINUTES
return UnitOfTime.MINUTES

@property
def icon(self) -> str:
Expand Down Expand Up @@ -277,7 +280,7 @@ def state(self) -> StateType:

@property
def unit_of_measurement(self) -> str:
return TIME_MINUTES
return UnitOfTime.MINUTES

@property
def icon(self) -> str:
Expand Down Expand Up @@ -350,7 +353,7 @@ def state(self) -> StateType:

@property
def unit_of_measurement(self) -> str:
return TEMP_CELSIUS
return UnitOfTemperature.CELSIUS

@property
def icon(self) -> str:
Expand Down Expand Up @@ -432,7 +435,7 @@ def state(self) -> StateType:

@property
def unit_of_measurement(self) -> str:
return TIME_MINUTES
return UnitOfTime.MINUTES

@property
def icon(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pytest-homeassistant-custom-component==0.13.114
pytest-homeassistant-custom-component~=0.13.114

# Component dependencies
backoff~=2.0
Expand Down
16 changes: 8 additions & 8 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async def test_no_encryption_detected(hass, detect_no_encryption): # pylint: dis
)

# Check that the config flow shows the user form as the first step
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["type"] == data_entry_flow.FlowResultType.FORM
assert result["step_id"] == "user"

result = await hass.config_entries.flow.async_configure(
Expand All @@ -75,7 +75,7 @@ async def test_no_encryption_detected(hass, detect_no_encryption): # pylint: dis

# Check that the config flow is complete and a new entry is created with
# the input data
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert result["title"] == "Candy"
assert result["data"] == {
CONF_IP_ADDRESS: "192.168.0.66",
Expand All @@ -93,7 +93,7 @@ async def test_detected_encryption_and_key_found(hass, detect_encryption_find_ke
)

# Check that the config flow shows the user form as the first step
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["type"] == data_entry_flow.FlowResultType.FORM
assert result["step_id"] == "user"

result = await hass.config_entries.flow.async_configure(
Expand All @@ -102,7 +102,7 @@ async def test_detected_encryption_and_key_found(hass, detect_encryption_find_ke

# Check that the config flow is complete and a new entry is created with
# the input data
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert result["title"] == "Candy"
assert result["data"] == {
CONF_IP_ADDRESS: "192.168.0.66",
Expand All @@ -120,14 +120,14 @@ async def test_detected_encryption_and_key_not_found(hass, detect_encryption_key
)

# Check that the config flow shows the user form as the first step
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["type"] == data_entry_flow.FlowResultType.FORM
assert result["step_id"] == "user"

result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_IP_ADDRESS: "192.168.0.66"}
)

assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["type"] == data_entry_flow.FlowResultType.FORM

assert result["errors"] == {"base": "detect_encryption"}

Expand All @@ -140,7 +140,7 @@ async def test_detected_encryption_without_key(hass, detect_encryption_without_k
)

# Check that the config flow shows the user form as the first step
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["type"] == data_entry_flow.FlowResultType.FORM
assert result["step_id"] == "user"

result = await hass.config_entries.flow.async_configure(
Expand All @@ -149,7 +149,7 @@ async def test_detected_encryption_without_key(hass, detect_encryption_without_k

# Check that the config flow is complete and a new entry is created with
# the input data
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert result["title"] == "Candy"
assert result["data"] == {
CONF_IP_ADDRESS: "192.168.0.66",
Expand Down

0 comments on commit fed64a7

Please sign in to comment.