Skip to content

Commit

Permalink
Merge pull request #30 from chises/29-cant-use-filllevelquantity-as-s…
Browse files Browse the repository at this point in the history
…tatics-entry

SensorStateClass and rename usageCounter
  • Loading branch information
chises authored Mar 13, 2023
2 parents d1cb0e9 + da331b9 commit fa9b502
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion custom_components/oilfox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
],
"iot_class": "cloud_polling",
"loggers": ["oilfox_component"],
"version": "0.1.8"
"version": "0.1.9"
}
26 changes: 16 additions & 10 deletions custom_components/oilfox/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
KWH_PER_L_OIL = 9.8

SENSORS = {
# index 0 = API Name
# index 0 = API Name & unique ID
# index 1 = units of measurement
# index 2 = icon
# index 3 = HA name
# index 3 = HA friendly name
# index 4 = device class
# index 5 = state class
"fillLevelPercent": [
Expand All @@ -50,15 +50,15 @@
"mdi:percent",
"fillLevelPercent",
None,
None,
SensorStateClass.TOTAL,
],
"fillLevelQuantity": [
"fillLevelQuantity",
VOLUME_LITERS,
"mdi:hydraulic-oil-level",
"fillLevelQuantity",
SensorDeviceClass.VOLUME,
None,
SensorStateClass.TOTAL,
],
"daysReach": [
"daysReach",
Expand Down Expand Up @@ -104,7 +104,7 @@
"usageCounter",
ENERGY_KILO_WATT_HOUR,
"mdi:barrel",
"usageCounter",
"energyConsumption",
SensorDeviceClass.ENERGY,
SensorStateClass.TOTAL_INCREASING,
],
Expand Down Expand Up @@ -378,8 +378,16 @@ def icon(self) -> str:

@property
def unique_id(self) -> str:
"""Return the name of the sensor."""
return "OilFox-" + self.oilfox.hwid + "-" + self.sensor[3]
"""Return the unique_id of the sensor."""

"""
Dirty workaround: entites meteringAt did use self.sensor[3] instead of self.sensor[0] as ID before ha-oilfox version 0.1.8
"""
if self.sensor[0] == "currentMeteringAt":
return "OilFox-" + self.oilfox.hwid + "-" + self.sensor[3]
if self.sensor[0] == "nextMeteringAt":
return "OilFox-" + self.oilfox.hwid + "-" + self.sensor[3]
return "OilFox-" + self.oilfox.hwid + "-" + self.sensor[0]

@property
def name(self) -> str:
Expand All @@ -405,8 +413,6 @@ def state_class(self) -> SensorStateClass:
def device_info(self) -> DeviceInfo:
"""Return the device info."""
return DeviceInfo(
identifiers={
(DOMAIN, self.oilfox.hwid)
},
identifiers={(DOMAIN, self.oilfox.hwid)},
name="OilFox-" + self.oilfox.hwid,
)

0 comments on commit fa9b502

Please sign in to comment.