Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix alerts #59

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [ 3.9 ]
python-version: [ 3.10.13 ]

steps:
- uses: actions/checkout@v1
Expand Down
25 changes: 18 additions & 7 deletions custom_components/pgnig_gas_sensor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import voluptuous as vol
from homeassistant.components.sensor import SensorEntity, PLATFORM_SCHEMA, SensorStateClass, SensorDeviceClass
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, VOLUME_CUBIC_METERS
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, UnitOfVolume
from homeassistant.core import HomeAssistant
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, HomeAssistantType


from .Invoices import InvoicesList
from .PgnigApi import PgnigApi
from .PpgReadingForMeter import MeterReading
Expand Down Expand Up @@ -70,7 +71,7 @@ async def async_setup_platform(

class PgnigSensor(SensorEntity):
def __init__(self, hass, api: PgnigApi, meter_id: string, id_local: int) -> None:
self._attr_native_unit_of_measurement = VOLUME_CUBIC_METERS
self._attr_native_unit_of_measurement = UnitOfVolume.CUBIC_METERS
self._attr_device_class = SensorDeviceClass.GAS
self._attr_state_class = SensorStateClass.TOTAL_INCREASING
self._state: MeterReading | None = None
Expand Down Expand Up @@ -109,7 +110,7 @@ def extra_state_attributes(self):
attrs = dict()
if self._state is not None:
attrs["wear"] = self._state.wear
attrs["wear_unit_of_measurment"] = VOLUME_CUBIC_METERS
attrs["wear_unit_of_measurment"] = UnitOfVolume.CUBIC_METERS
return attrs

async def async_update(self):
Expand Down Expand Up @@ -213,6 +214,16 @@ def __init__(self, hass, api: PgnigApi, meter_id: string, id_local: int) -> None
def unique_id(self) -> str | None:
return "pgnig_cost_tracking_sensor" + self.meter_id + "_" + str(self.id_local)

@property
def device_info(self):
return {
"identifiers": {("pgnig_gas_sensor", self.meter_id)},
"name": f"PGNIG GAS METER ID {self.meter_id}",
"manufacturer": "PGNIG",
"model": self.meter_id,
"via_device": None,
}

@property
def name(self) -> str:
return self.entity_name
Expand Down Expand Up @@ -243,10 +254,10 @@ def latest_price(self):

def upcoming_payment_for_meter(x: InvoicesList):
return id_local == x.id_pp \
and x.wear is not None \
and x.wear != 0 \
and x.gross_amount is not None \
and x.gross_amount != 0
and x.wear is not None \
and x.wear != 0 \
and x.gross_amount is not None \
and x.gross_amount != 0

return max(filter(upcoming_payment_for_meter, self.api.invoices().invoices_list),
key=lambda z: z.date,
Expand Down
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Strictly for tests
pytest-homeassistant-custom-component==0.11.6
pytest-homeassistant-custom-component==0.13.20
Loading