Skip to content

Commit

Permalink
pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ldotlopez committed Sep 22, 2024
1 parent ca2eeb5 commit f8b4f20
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 88 deletions.
3 changes: 1 addition & 2 deletions custom_components/hnap_device/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"""Binary sensor for HNAP device integration."""

import logging
from typing import Optional

import hnap
import requests.exceptions
Expand Down Expand Up @@ -74,7 +73,7 @@ async def async_setup_entry(
unique_id=f"{config_entry.entry_id}-{PLATFORM}",
device_info=device_info,
device=device,
auto_reboot=config_entry.options[CONF_AUTO_REBOOT],
auto_reboot=config_entry.options.get(CONF_AUTO_REBOOT, True),
)
],
update_before_add=True,
Expand Down
15 changes: 8 additions & 7 deletions custom_components/hnap_device/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@

"""Constants for HNAP device integration."""

DOMAIN = "hnap_device"

CONF_AUTO_REBOOT = "auto_reboot"
CONF_PLATFORMS = "platforms"
PLATFORM_CAMERA = "camera"
PLATFORM_BINARY_SENSOR = "binary_sensor"
PLATFORM_SIREN = "siren"
DEFAULT_AUTO_REBOOT = False
DEFAULT_USERNAME = "admin"
DOMAIN = "hnap_device"
MAX_FAILURES_BEFORE_UNAVAILABLE = 3
MAX_UPTIME_BEFORE_REBOOT = 60 * 60 * 12 # 12 hours
DEFAULT_USERNAME = "admin"
DEFAULT_AUTO_REBOOT = False
CONF_AUTO_REBOOT = "auto_reboot"
PLATFORM_BINARY_SENSOR = "binary_sensor"
PLATFORM_CAMERA = "camera"
PLATFORM_SIREN = "siren"
3 changes: 2 additions & 1 deletion custom_components/hnap_device/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def hnap_update_success(self):
if self._auto_reboot:
uptime = time.monotonic() - self._boot_ts
_LOGGER.debug(
f"{self.entity_id}: device uptime {uptime:.2f}s / {MAX_UPTIME_BEFORE_REBOOT}s"
f"{self.entity_id}: device uptime {uptime:.2f}s "
+ f"/ {MAX_UPTIME_BEFORE_REBOOT}s"
)

if self.available and uptime > MAX_UPTIME_BEFORE_REBOOT:
Expand Down
37 changes: 18 additions & 19 deletions custom_components/hnap_device/manifest.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
{
"domain" : "hnap_device",
"name" : "HNAP device",
"codeowners" : [
"@ldotlopez"
],
"config_flow" : true,
"dependencies" : [],
"dhcp" : [
],
"documentation" : "https://github.com/ldotlopez/ha-hnap-device",
"homekit" : {},
"iot_class" : "local_polling",
"issue_tracker" : "https://github.com/ldotlopez/ha-hnap-device/issues",
"requirements" : [
"hnap>=1.0.1,<2.0.0"
],
"ssdp" : [],
"version" : "1.1.1",
"zeroconf" : []
"domain": "hnap_device",
"name": "HNAP device",
"codeowners": [
"@ldotlopez"
],
"config_flow": true,
"dependencies": [],
"dhcp": [],
"documentation": "https://github.com/ldotlopez/ha-hnap-device",
"homekit": {},
"iot_class": "local_polling",
"issue_tracker": "https://github.com/ldotlopez/ha-hnap-device/issues",
"requirements": [
"hnap>=1.0.1,<2.0.0"
],
"ssdp": [],
"version": "1.1.2",
"zeroconf": []
}
2 changes: 1 addition & 1 deletion custom_components/hnap_device/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ call:
required: false
advanced: false
selector:
object:
object:
11 changes: 8 additions & 3 deletions custom_components/hnap_device/siren.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"""Siren sensor for HNAP device integration."""

import logging
from typing import Optional

import hnap
import requests.exceptions
Expand All @@ -46,7 +45,11 @@


class HNAPSiren(HNapEntity, SirenEntity):
def __init__(self, *args, **kwargs):
def __init__(
self,
*args,
**kwargs,
):
super().__init__(*args, **kwargs, name="siren", domain=SIREN_DOMAIN)
self._attr_is_on = False
self._attr_supported_features = (
Expand All @@ -72,7 +75,9 @@ def update(self):
else:
self.hnap_update_success()

def turn_on(self, volume_level=1, duration=15, tone="police") -> None:
def turn_on(
self, volume_level: float = 1.0, duration: int = 15, tone: str = "police"
) -> None:
self.device.play(
sound=hnap.SirenSound.fromstring(tone),
volume=int(volume_level * 100),
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hnap_device/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
}
}
}
}
}
54 changes: 27 additions & 27 deletions custom_components/hnap_device/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{
"config": {
"abort": {
"already_configured": "Device is already configured"
},
"error": {
"cannot_connect": "Failed to connect",
"invalid_auth": "Invalid authentication",
"invalid_device_type": "Invalid device type",
"unknown": "Unexpected error"
},
"step": {
"user": {
"data": {
"host": "Host",
"password": "Password",
"username": "Username"
}
}
}
"config": {
"abort": {
"already_configured": "Device is already configured"
},
"error": {
"cannot_connect": "Failed to connect",
"invalid_auth": "Invalid authentication",
"invalid_device_type": "Invalid device type",
"unknown": "Unexpected error"
},
"options": {
"step": {
"init": {
"data": {
"auto_reboot": "Reboot device each 12 hours"
}
}
"step": {
"user": {
"data": {
"host": "Host",
"password": "Password",
"username": "Username"
}
}
}
},
"options": {
"step": {
"init": {
"data": {
"auto_reboot": "Reboot device each 12 hours"
}
}
}
}
}
}
16 changes: 8 additions & 8 deletions custom_components/hnap_device/translations/es.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"options": {
"step": {
"init": {
"data": {
"auto_reboot": "Reiniciar el dispositivo cada 12 horas"
}
}
"options": {
"step": {
"init": {
"data": {
"auto_reboot": "Reiniciar el dispositivo cada 12 horas"
}
}
}
}
}
}
36 changes: 18 additions & 18 deletions custom_components/hnap_device/translations/it.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"config": {
"abort": {
"already_configured": "Il Dispositivo è già configurato"
},
"error": {
"cannot_connect": "Impossibile connettersi",
"invalid_auth": "Autenticazione non valida",
"invalid_device_type": "Tipo disponisitivo non valido",
"unknown": "Errore imprevisto"
},
"step": {
"user": {
"data": {
"host": "Host",
"password": "Password",
"username": "Username"
}
}
"config": {
"abort": {
"already_configured": "Il Dispositivo \u00e8 gi\u00e0 configurato"
},
"error": {
"cannot_connect": "Impossibile connettersi",
"invalid_auth": "Autenticazione non valida",
"invalid_device_type": "Tipo disponisitivo non valido",
"unknown": "Errore imprevisto"
},
"step": {
"user": {
"data": {
"host": "Host",
"password": "Password",
"username": "Username"
}
}
}
}
}
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"name": "HNAP device",
"render_readme": true,
"content_in_root": false,
"homeassistant": "2023.6.0",
"homeassistant": "2023.6.0"
}

0 comments on commit f8b4f20

Please sign in to comment.