Skip to content

Commit

Permalink
Merge pull request #539 from stickpin/master
Browse files Browse the repository at this point in the history
  • Loading branch information
robinostlund authored Jan 7, 2024
2 parents 453c0b9 + e1bd0b7 commit df1dca2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions custom_components/volkswagencarnet/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
import logging

from homeassistant.components.device_tracker import SOURCE_TYPE_GPS
from homeassistant.components.device_tracker import SourceType
from homeassistant.components.device_tracker.config_entry import TrackerEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.dispatcher import async_dispatcher_connect
Expand Down Expand Up @@ -48,7 +48,7 @@ async def see_vehicle():
await async_see(
dev_id=dev_id,
host_name=host_name,
source_type=SOURCE_TYPE_GPS,
source_type=SourceType.GPS,
gps=instrument.state,
icon="mdi:car",
)
Expand All @@ -72,7 +72,7 @@ def longitude(self) -> float:
@property
def source_type(self):
"""Return the source type, eg gps or router, of the device."""
return SOURCE_TYPE_GPS
return SourceType.GPS

@property
def icon(self):
Expand Down
18 changes: 13 additions & 5 deletions custom_components/volkswagencarnet/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
DEVICE_CLASSES,
STATE_CLASSES,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant

from . import VolkswagenEntity
from .const import DATA_KEY, DATA, DOMAIN
from .const import DATA_KEY, DATA, DOMAIN, UPDATE_CALLBACK

_LOGGER = logging.getLogger(__name__)


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
async def async_setup_platform(hass: HomeAssistant, config: ConfigEntry, async_add_entities, discovery_info=None):
"""Set up the Volkswagen sensors."""
if discovery_info is None:
return
Expand All @@ -29,7 +31,13 @@ async def async_setup_entry(hass, entry, async_add_devices):
coordinator = data.coordinator
if coordinator.data is not None:
async_add_devices(
VolkswagenSensor(data=data, vin=coordinator.vin, component=instrument.component, attribute=instrument.attr)
VolkswagenSensor(
data=data,
vin=coordinator.vin,
component=instrument.component,
attribute=instrument.attr,
callback=hass.data[DOMAIN][entry.entry_id][UPDATE_CALLBACK],
)
for instrument in (instrument for instrument in data.instruments if instrument.component == "sensor")
)

Expand All @@ -40,7 +48,7 @@ class VolkswagenSensor(VolkswagenEntity, SensorEntity):
"""Representation of a Volkswagen WeConnect Sensor."""

@property
def _attr_native_value(self):
def native_value(self):
"""Return the state of the sensor."""
if self.instrument is not None:
_LOGGER.debug("Getting state of %s" % self.instrument.attr)
Expand All @@ -51,7 +59,7 @@ def _attr_native_value(self):
return self.instrument.state

@property
def _attr_native_unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
if self.instrument.unit:
return self.instrument.unit
Expand Down

0 comments on commit df1dca2

Please sign in to comment.