Skip to content

Commit

Permalink
Merge pull request #221 from itchannel/1.39
Browse files Browse the repository at this point in the history
1.39
  • Loading branch information
itchannel authored Nov 30, 2022
2 parents f4f8dd6 + 25bd8e8 commit 9a2b791
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion custom_components/fordpass/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
REGION_OPTIONS = ["UK&Europe", "Australia", "North America & Canada"]

SENSORS = {
"odometer": {"icon": "mdi:counter"},
"odometer": {"icon": "mdi:counter", "state_class": "total", "device_class": "distance"},
"fuel": {"icon": "mdi:gas-station"},
"battery": {"icon": "mdi:car-battery"},
"oil": {"icon": "mdi:oil"},
Expand Down
2 changes: 1 addition & 1 deletion custom_components/fordpass/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def device_id(self):

@property
def extra_state_attributes(self):
return self.coordinator.data[self.sensor].items()
return None

@property
def icon(self):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/fordpass/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://github.com/itchannel/fordpass-ha",
"issue_tracker": "https://github.com/itchannel/fordpass-ha/issues",
"version": "0.1.38",
"version": "0.1.39",
"requirements": [],
"ssdp": [],
"zeroconf": [],
Expand Down
31 changes: 29 additions & 2 deletions custom_components/fordpass/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle, dt

from homeassistant.components.sensor import (
SensorEntity,
SensorDeviceClass,
SensorStateClass
)

from . import FordPassEntity
from .const import CONF_DISTANCE_UNIT, CONF_PRESSURE_UNIT, DOMAIN, SENSORS


_LOGGER = logging.getLogger(__name__)


Expand All @@ -30,7 +37,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):

class CarSensor(
FordPassEntity,
Entity,
SensorEntity,
):
def __init__(self, coordinator, sensor, options):

Expand Down Expand Up @@ -394,9 +401,29 @@ def extra_state_attributes(self):
return self.get_value("attribute")

@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
return self.get_value("measurement")

@property
def icon(self):
return SENSORS[self.sensor]["icon"]

@property
def state_class(self):
if "state_class" in SENSORS[self.sensor]:
if SENSORS[self.sensor]["state_class"] is "total":
return SensorStateClass.TOTAL
elif SENSORS[self.sensor]["state_class"] is "measurement":
return SensorStateClass.MEASUREMENT
else:
return None
else:
return None

@property
def device_class(self):
if "device_class" in SENSORS[self.sensor]:
if SENSORS[self.sensor]["device_class"] is "distance":
return SensorDeviceClass.DISTANCE
else:
return None
3 changes: 3 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

## **Changelog**
### Version 1.39
- added statistics support to odometer sensor
- Fixed device_tracker not working correctly in automations
### Version 1.38
- Changed the default update interval from 5 minutes to 15 minutes (Reduce Ford API Requests)
- Add ability to change this interval in integration options (WARNING! setting this too low will result in your Fordpass account being locked!!!!)
Expand Down

0 comments on commit 9a2b791

Please sign in to comment.