Skip to content

Commit

Permalink
Add HMI brightness entity (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinse authored Oct 27, 2024
1 parent 1b16292 commit ca56c83
Showing 6 changed files with 64 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

## 0.7.2b1

* Add support for setting status light brightness, #112
* Add retry on 500 server errors from Zaptec cloud, #90
* Added new charger lock "Permanent cable lock" and removed the binary
sensor of the same name #102
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -100,6 +100,7 @@ supported by the API. Use at own risk and they might break at any time.
> * Setting charger min and max current
> * Authorize charging
> * Setting cable lock
> * Setting status light brightness
## Zaptec device concept

14 changes: 14 additions & 0 deletions custom_components/zaptec/api.py
Original file line number Diff line number Diff line change
@@ -729,6 +729,20 @@ async def set_permanent_cable_lock(self, lock: bool):
f"chargers/{self.id}/localSettings", method="post", data=data
)
return result

async def set_hmi_brightness(self, brightness: float):
"""Set the HMI brightness"""
_LOGGER.debug("Set HMI brightness %s", brightness)
data = {
"Device": {
"HmiBrightness": brightness,
},
}
# NOTE: Undocumented API call
result = await self._account._request(
f"chargers/{self.id}/localSettings", method="post", data=data
)
return result


class Account:
46 changes: 44 additions & 2 deletions custom_components/zaptec/number.py
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import ZaptecBaseEntity, ZaptecUpdateCoordinator
from .api import Installation
from .api import Installation, Charger
from .const import DOMAIN

_LOGGER = logging.getLogger(__name__)
@@ -38,6 +38,7 @@ def _update_from_zaptec(self) -> None:

class ZaptecAvailableCurrentNumber(ZaptecNumber):
zaptec_obj: Installation
entity_description: ZapNumberEntityDescription

def _post_init(self):
# Get the max current rating from the reported max current
@@ -64,7 +65,8 @@ async def async_set_native_value(self, value: float) -> None:


class ZaptecSettingNumber(ZaptecNumber):
zaptec_obj: Installation
zaptec_obj: Charger
entity_description: ZapNumberEntityDescription

def _post_init(self):
# Get the max current rating from the reported max current
@@ -93,6 +95,38 @@ async def async_set_native_value(self, value: float) -> None:
await self.coordinator.async_request_refresh()


class ZaptecHmiBrightness(ZaptecNumber):
zaptec_obj: Charger
entity_description: ZapNumberEntityDescription

@callback
def _update_from_zaptec(self) -> None:
try:
self._attr_native_value = float(self._get_zaptec_value()) * 100
self._attr_available = True
self._log_value(self._attr_native_value)
except (KeyError, AttributeError):
self._attr_available = False
self._log_unavailable()

async def async_set_native_value(self, value: float) -> None:
"""Update to Zaptec."""
_LOGGER.debug(
"Set %s to <%s> %s in %s",
self.entity_id,
type(value).__qualname__,
value,
self.zaptec_obj.qual_id,
)

try:
await self.zaptec_obj.set_hmi_brightness(value / 100)
except Exception as exc:
raise HomeAssistantError(f"Set HmiBrightness to {value} failed") from exc

await self.coordinator.async_request_refresh()


@dataclass
class ZapNumberEntityDescription(NumberEntityDescription):
cls: type | None = None
@@ -139,6 +173,14 @@ class ZapNumberEntityDescription(NumberEntityDescription):
cls=ZaptecSettingNumber,
setting="CurrentInMaximum",
),
ZapNumberEntityDescription(
key="hmi_brightness",
translation_key="hmi_brightness",
entity_category=EntityCategory.DIAGNOSTIC,
icon="mdi:brightness-6",
native_unit_of_measurement=const.PERCENTAGE,
cls=ZaptecHmiBrightness,
),
]


3 changes: 2 additions & 1 deletion custom_components/zaptec/translations/en.json
Original file line number Diff line number Diff line change
@@ -98,7 +98,8 @@
"number": {
"available_current": { "name": "Available current" },
"charger_max_current": { "name": "Charger max current" },
"charger_min_current": { "name": "Charger min current" }
"charger_min_current": { "name": "Charger min current" },
"hmi_brightness": { "name": "Status indicator brightness" }
},
"binary_sensor": {
"authorization_required": {
3 changes: 2 additions & 1 deletion custom_components/zaptec/translations/nl.json
Original file line number Diff line number Diff line change
@@ -98,7 +98,8 @@
"number": {
"available_current": { "name": "Beschikbare stroom" },
"charger_max_current": { "name": "Max stroom" },
"charger_min_current": { "name": "Min stroom" }
"charger_min_current": { "name": "Min stroom" },
"hmi_brightness": { "name": "Helderheid statusindicator" }
},
"binary_sensor": {
"authorization_required": {

0 comments on commit ca56c83

Please sign in to comment.