diff --git a/custom_components/hnap_device/binary_sensor.py b/custom_components/hnap_device/binary_sensor.py index 92f7006..699ef12 100644 --- a/custom_components/hnap_device/binary_sensor.py +++ b/custom_components/hnap_device/binary_sensor.py @@ -19,7 +19,6 @@ """Binary sensor for HNAP device integration.""" import logging -from typing import Optional import hnap import requests.exceptions @@ -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, diff --git a/custom_components/hnap_device/const.py b/custom_components/hnap_device/const.py index 6092d28..03bf9e5 100644 --- a/custom_components/hnap_device/const.py +++ b/custom_components/hnap_device/const.py @@ -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" diff --git a/custom_components/hnap_device/entity.py b/custom_components/hnap_device/entity.py index d776213..48ba0ea 100644 --- a/custom_components/hnap_device/entity.py +++ b/custom_components/hnap_device/entity.py @@ -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: diff --git a/custom_components/hnap_device/manifest.json b/custom_components/hnap_device/manifest.json index c73c811..be51cc7 100644 --- a/custom_components/hnap_device/manifest.json +++ b/custom_components/hnap_device/manifest.json @@ -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": [] } diff --git a/custom_components/hnap_device/services.yaml b/custom_components/hnap_device/services.yaml index 114e614..468833d 100644 --- a/custom_components/hnap_device/services.yaml +++ b/custom_components/hnap_device/services.yaml @@ -57,4 +57,4 @@ call: required: false advanced: false selector: - object: \ No newline at end of file + object: diff --git a/custom_components/hnap_device/siren.py b/custom_components/hnap_device/siren.py index 7c5f8c7..6f397f8 100644 --- a/custom_components/hnap_device/siren.py +++ b/custom_components/hnap_device/siren.py @@ -20,7 +20,6 @@ """Siren sensor for HNAP device integration.""" import logging -from typing import Optional import hnap import requests.exceptions @@ -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 = ( @@ -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), diff --git a/custom_components/hnap_device/strings.json b/custom_components/hnap_device/strings.json index 55173af..ae6423a 100644 --- a/custom_components/hnap_device/strings.json +++ b/custom_components/hnap_device/strings.json @@ -28,4 +28,4 @@ } } } -} \ No newline at end of file +} diff --git a/custom_components/hnap_device/translations/en.json b/custom_components/hnap_device/translations/en.json index a0aa68c..be0022d 100644 --- a/custom_components/hnap_device/translations/en.json +++ b/custom_components/hnap_device/translations/en.json @@ -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" } + } } -} \ No newline at end of file + } +} diff --git a/custom_components/hnap_device/translations/es.json b/custom_components/hnap_device/translations/es.json index 64ef2d3..89c27a1 100644 --- a/custom_components/hnap_device/translations/es.json +++ b/custom_components/hnap_device/translations/es.json @@ -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" } + } } -} \ No newline at end of file + } +} diff --git a/custom_components/hnap_device/translations/it.json b/custom_components/hnap_device/translations/it.json index 14a2666..43b57b4 100644 --- a/custom_components/hnap_device/translations/it.json +++ b/custom_components/hnap_device/translations/it.json @@ -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" } + } } + } } diff --git a/hacs.json b/hacs.json index a1764fc..373b702 100644 --- a/hacs.json +++ b/hacs.json @@ -2,5 +2,5 @@ "name": "HNAP device", "render_readme": true, "content_in_root": false, - "homeassistant": "2023.6.0", + "homeassistant": "2023.6.0" }