Skip to content

Commit

Permalink
Added support for long term statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
elad-bar committed Dec 12, 2021
1 parent 9e413fc commit 04247cb
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.5

- Added support for long term statistics

## 1.0.4

- Upgraded code to support breaking changes of HA v2012.12.0
Expand Down
7 changes: 6 additions & 1 deletion custom_components/hpprinter/helpers/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
DOMAIN as DOMAIN_BINARY_SENSOR,
BinarySensorDeviceClass,
)
from homeassistant.components.sensor import DOMAIN as DOMAIN_SENSOR, SensorDeviceClass
from homeassistant.components.sensor import (
DOMAIN as DOMAIN_SENSOR,
SensorDeviceClass,
SensorStateClass,
)

MANUFACTURER = "HP"
DEFAULT_NAME = "HP Printer"
Expand Down Expand Up @@ -43,6 +47,7 @@
ENTITY_UNIQUE_ID = "unique-id"
ENTITY_BINARY_SENSOR_DEVICE_CLASS = "binary-sensor-device-class"
ENTITY_SENSOR_DEVICE_CLASS = "sensor-device-class"
ENTITY_SENSOR_STATE_CLASS = "sensor-state-class"

ENTITY_STATUS = "entity-status"
ENTITY_STATUS_EMPTY = None
Expand Down
3 changes: 3 additions & 0 deletions custom_components/hpprinter/managers/entity_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ def create_printer_sensor(self):
entity.icon = PAGES_ICON
entity.device_name = device_name
entity.state = state
entity.sensor_state_class = SensorStateClass.TOTAL_INCREASING

self.set_entity(DOMAIN_SENSOR, entity_name, entity)

Expand Down Expand Up @@ -339,6 +340,7 @@ def create_scanner_sensor(self):
entity.icon = SCANNER_ICON
entity.device_name = device_name
entity.state = state
entity.sensor_state_class = SensorStateClass.TOTAL_INCREASING

self.set_entity(DOMAIN_SENSOR, entity_name, entity)

Expand All @@ -364,6 +366,7 @@ def create_cartridge_sensor(self, cartridge, key):
entity.icon = INK_ICON
entity.device_name = device_name
entity.state = state
entity.sensor_state_class = SensorStateClass.MEASUREMENT

self.set_entity(DOMAIN_SENSOR, entity_name, entity)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/hpprinter/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"after_dependencies": [ "logger" ],
"requirements": ["xmltodict==0.12.0"],
"config_flow": true,
"version": "1.0.3",
"version": "1.0.5",
"iot_class": "local_polling"
}
5 changes: 4 additions & 1 deletion custom_components/hpprinter/models/entity_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class EntityData:
disabled: bool
binary_sensor_device_class: Optional[BinarySensorDeviceClass]
sensor_device_class: Optional[SensorDeviceClass]
sensor_state_class: Optional[SensorStateClass]

def __init__(self):
self.unique_id = ""
Expand All @@ -26,6 +27,7 @@ def __init__(self):
self.disabled = False
self.binary_sensor_device_class = None
self.sensor_device_class = None
self.sensor_state_class = None

def __repr__(self):
obj = {
Expand All @@ -38,7 +40,8 @@ def __repr__(self):
ENTITY_UNIQUE_ID: self.unique_id,
ENTITY_DISABLED: self.disabled,
ENTITY_BINARY_SENSOR_DEVICE_CLASS: self.binary_sensor_device_class,
ENTITY_SENSOR_DEVICE_CLASS: self.sensor_device_class
ENTITY_SENSOR_DEVICE_CLASS: self.sensor_device_class,
ENTITY_SENSOR_STATE_CLASS: self.sensor_state_class
}

to_string = f"{obj}"
Expand Down
5 changes: 5 additions & 0 deletions custom_components/hpprinter/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def device_class(self) -> SensorDeviceClass | str | None:
"""Return the class of this sensor."""
return self.entity.sensor_device_class

@property
def state_class(self) -> SensorStateClass | str | None:
"""Return the class of this sensor."""
return self.entity.sensor_state_class

async def async_added_to_hass_local(self):
_LOGGER.info(f"Added new {self.name}")

Expand Down

0 comments on commit 04247cb

Please sign in to comment.