Skip to content

Commit

Permalink
gas price entity
Browse files Browse the repository at this point in the history
  • Loading branch information
mcapmari committed Jan 10, 2025
1 parent 6a4a55d commit c3f726a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion custom_components/djv_meter/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"domain": "djv_meter",
"name": "DJV-COM Meter",
"integration_type": "hub",
"version": "1.1.0",
"version": "1.2.0",
"config_flow": true,
"documentation": "https://github.com/mcapmari/ha-djv_meter",
"requirements": ["requests>=2.28.0"],
Expand Down
14 changes: 11 additions & 3 deletions custom_components/djv_meter/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class DJVMeterSensorDescription(SensorEntityDescription):

SENSOR_TYPES: Final[tuple[DJVMeterSensorDescription, ...]] = (
DJVMeterSensorDescription(
key="meter_indications", # Updated key to match desired entity_id
key="meter_indications",
name="Meter Indications",
native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
device_class=SensorDeviceClass.GAS,
state_class=SensorStateClass.TOTAL_INCREASING,
value_fn=lambda data: float(data["counter_indications"]),
),
DJVMeterSensorDescription(
key="last_day_consumption", # Updated key to match desired entity_id
key="last_day_consumption",
name="Last Day",
native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
device_class=SensorDeviceClass.GAS,
Expand All @@ -55,6 +55,14 @@ class DJVMeterSensorDescription(SensorEntityDescription):
state_class=SensorStateClass.TOTAL,
value_fn=lambda data: float(data["sum"]),
),
DJVMeterSensorDescription(
key="gas_price",
name="Gas Price",
native_unit_of_measurement="MDL/m³",
device_class=SensorDeviceClass.MONETARY,
state_class=SensorStateClass.TOTAL,
value_fn=lambda data: float(data["counter_settings"]["price"]["price"][0]),
),
)

async def async_setup_entry(
Expand Down Expand Up @@ -115,4 +123,4 @@ def native_value(self) -> StateType:
for meter_data in self.coordinator.data["data"]:
if meter_data["tsd_id"] == self._meter_data["tsd_id"]:
return self.entity_description.value_fn(meter_data)
return None
return None

0 comments on commit c3f726a

Please sign in to comment.