Skip to content

Commit

Permalink
Merge pull request #23 from masaccio/masaccio/issue17
Browse files Browse the repository at this point in the history
Masaccio/issue17
  • Loading branch information
masaccio authored Jan 5, 2024
2 parents 74b75e0 + d6988a0 commit 9c51d46
Show file tree
Hide file tree
Showing 13 changed files with 1,620 additions and 950 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"editor.wordWrapColumn": 100,
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
}
},
"black-formatter.args": [
Expand Down
12 changes: 12 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
🪲 indicates bug fixes
🚀 indicates new features or improvements

## v1.6.4

🪲 Fixes load failure [issue-18](https://github.com/masaccio/ha-kingspan-watchman-sensit/issues/18) on newer versions of Home Assistant Core.

## v1.6.3

Minor bug fixes:

🪲 Remove 'Unsupported state class' for tank capacity ([issue-17](https://github.com/masaccio/ha-kingspan-watchman-sensit/issues/17))
🪲 Threshold for a refill changed to +10% for calculating daily usage ([issue-15](https://github.com/masaccio/ha-kingspan-watchman-sensit/issues/15))
🪲 Allow setup of the integration before any readings have been sent to Kingspan's servers ([issue-14](https://github.com/masaccio/ha-kingspan-watchman-sensit/issues/14))

## v1.6.2

🪲 Fixes load failure [issue-10](https://github.com/masaccio/ha-kingspan-watchman-sensit/issues/10) on newer versions of Home Assistant Core. The minimum version is now 2023.10.0.
Expand Down
7 changes: 5 additions & 2 deletions custom_components/kingspan_watchman_sensit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
try:
_ = await client.check_credentials()
except APIError as e:
_LOGGER.debug("Credentials check for username '%s' failed: %s", username, e)
raise ConfigEntryAuthFailed("Credentials invalid") from e
if "no level data" in str(e).lower():
_LOGGER.warning("No data available for username '%s'", username)
else:
_LOGGER.debug("Credentials check for username '%s' failed: %s", username, e)
raise ConfigEntryAuthFailed("Credentials invalid") from e
except TimeoutError as e:
_LOGGER.debug("Credentials check for username '%s' timed out: %s", username, e)
raise ConfigEntryNotReady("Timed out while connecting to Kingspan service") from e
Expand Down
2 changes: 1 addition & 1 deletion custom_components/kingspan_watchman_sensit/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
# Defaults
DEFAULT_TANK_NAME = "My Tank"
API_TIMEOUT = 30 # seconds
REFILL_THRESHOLD = 1.25 # factor considerd a tank refill
REFILL_THRESHOLD = 1.1 # factor considerd a tank refill
DEFAULT_USAGE_WINDOW = 14 # days
DEFAULT_UPDATE_INTERVAL = 8 # hours
4 changes: 2 additions & 2 deletions custom_components/kingspan_watchman_sensit/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/masaccio/ha-kingspan-watchman-sensit/issues",
"requirements": [
"kingspan-connect-sensor==3.0.2"
"kingspan-connect-sensor==3.0.3"
],
"version": "1.4.5"
"version": "1.6.4"
}
18 changes: 7 additions & 11 deletions custom_components/kingspan_watchman_sensit/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE, TIME_DAYS, UnitOfVolume
from homeassistant.const import PERCENTAGE, UnitOfTime, UnitOfVolume
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

Expand Down Expand Up @@ -50,9 +50,7 @@ class OilLevel(SENSiTEntity, SensorEntity):
@property
def native_value(self):
"""Return the oil level in litres"""
_LOGGER.debug(
"Read oil level: %d litres", self.coordinator.data[self.idx].level
)
_LOGGER.debug("Read oil level: %d litres", self.coordinator.data[self.idx].level)
return self.coordinator.data[self.idx].level

@property
Expand All @@ -73,8 +71,7 @@ class TankPercentageFull(SENSiTEntity, SensorEntity):
def native_value(self):
"""Return the oil level as a percentage"""
percent_full = 100 * (
self.coordinator.data[self.idx].level
/ self.coordinator.data[self.idx].capacity
self.coordinator.data[self.idx].level / self.coordinator.data[self.idx].capacity
)
_LOGGER.debug("Read oil level: %.1f percent", percent_full)
return Decimal(f"{percent_full:.1f}")
Expand All @@ -93,6 +90,7 @@ class TankCapacity(SENSiTEntity, SensorEntity):
_attr_name = "Tank Capacity"
_attr_device_class = SensorDeviceClass.VOLUME
_attr_native_unit_of_measurement = UnitOfVolume.LITERS
_attr_state_class = SensorStateClass.TOTAL

@property
def native_value(self):
Expand All @@ -112,9 +110,7 @@ class LastReadDate(SENSiTEntity, SensorEntity):
@property
def native_value(self):
"""Return date of the last reading"""
_LOGGER.debug(
"Tank last read %s", str(self.coordinator.data[self.idx].last_read)
)
_LOGGER.debug("Tank last read %s", str(self.coordinator.data[self.idx].last_read))
return self.coordinator.data[self.idx].last_read


Expand All @@ -129,14 +125,14 @@ class CurrentUsage(SENSiTEntity, SensorEntity):
def native_value(self):
"""Return the usage in the last day in litres"""
current_usage = self.coordinator.data[self.idx].usage_rate
_LOGGER.debug("Current oil usage %d days", current_usage)
_LOGGER.debug("Current oil usage %d litres/day", current_usage)
return Decimal(f"{current_usage:.1f}")


class ForcastEmpty(SENSiTEntity, SensorEntity):
_attr_icon = "mdi:calendar"
_attr_name = "Forecast Empty"
_attr_native_unit_of_measurement = TIME_DAYS
_attr_native_unit_of_measurement = UnitOfTime.DAYS
_attr_state_class = SensorStateClass.MEASUREMENT

@property
Expand Down
5 changes: 3 additions & 2 deletions maintenance/generate_manifest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#! /usr/bin/env poetry run python3
from connectsensor import __version__ as API_VERSON
import json

import toml
from connectsensor import __version__ as API_VERSON

MANIFEST = "custom_components/kingspan_watchman_sensit/manifest.json"

Expand All @@ -15,7 +16,7 @@
"documentation": "https://github.com/masaccio/ha-kingspan-watchman-sensit",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/masaccio/ha-kingspan-watchman-sensit/issues",
"requirements": [f"kingspan-connect-sensor=={API_VERSON}"],
"requirements": [f"kingspan-connect-sensor>={API_VERSON}"],
"version": pyproject["tool"]["poetry"]["version"],
}

Expand Down
Loading

0 comments on commit 9c51d46

Please sign in to comment.