Skip to content

Commit

Permalink
Update for 2021.12 changes
Browse files Browse the repository at this point in the history
- Timestamp/Date device class value changes
- DEVICE_CLASS_* constants deprecated
  • Loading branch information
make-all committed Dec 12, 2021
1 parent 8691dd1 commit 60ddbcd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion custom_components/metlink/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"issue_tracker": "https://github.com/make-all/metlink-nz/issues",
"name": "Metlink Wellington Transport",
"requirements": ["isodate==0.6.0"],
"version": "1.0.2"
"version": "1.0.3"
}
6 changes: 3 additions & 3 deletions custom_components/metlink/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from typing import Any, Callable, Dict, Optional

from homeassistant import config_entries, core
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorDeviceClass
from homeassistant.const import ATTR_ATTRIBUTION, CONF_API_KEY, DEVICE_CLASS_TIMESTAMP
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -178,7 +178,7 @@ def state(self):

@property
def device_class(self):
return DEVICE_CLASS_TIMESTAMP
return SensorDeviceClass.TIMESTAMP

@property
def device_state_attributes(self) -> Dict[str, Any]:
Expand Down Expand Up @@ -217,7 +217,7 @@ async def async_update(self):
# First record is the next departure, so use that
# to set the state (departure time)
next_departure = dt_util.parse_datetime(time)
self._state = time
self._state = next_departure
self._icon = OPERATOR_ICONS.get(
departure[ATTR_OPERATOR], DEFAULT_ICON
)
Expand Down
1 change: 1 addition & 0 deletions hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"render_readme": true,
"domains": ["sensor"],
"country": "NZ",
"homeassistant": "2021.12.0",
"iot_class": "Cloud Polling"
}
4 changes: 2 additions & 2 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async def test_async_update_success(hass, aioclient_mock):
assert sensor.icon == "mdi:train"
assert sensor.name == "Metlink WELL"
assert sensor.unique_id == "metlink_WELL_rKPL_dPorirua"
assert sensor.state == expected["departure"]
assert sensor.state == dt_util.parse_datetime(expected["departure"])


async def test_async_update_failed():
Expand Down Expand Up @@ -218,7 +218,7 @@ async def test_async_update_multiple(hass, aioclient_mock):
assert sensor.icon == "mdi:train"
assert sensor.name == "Metlink WELL"
assert sensor.unique_id == "metlink_WELL_rKPL"
assert sensor.state == expected["departure"]
assert sensor.state == dt_util.parse_datetime(expected["departure"])


def test_slug():
Expand Down

0 comments on commit 60ddbcd

Please sign in to comment.