diff --git a/.github/workflows/hassfest.yaml b/.github/workflows/hassfest.yaml index 862840e..7ec467f 100644 --- a/.github/workflows/hassfest.yaml +++ b/.github/workflows/hassfest.yaml @@ -1,5 +1,4 @@ --- - name: Validate with hassfest on: @@ -13,4 +12,11 @@ jobs: runs-on: "ubuntu-latest" steps: - uses: "actions/checkout@v2" + + - name: HACS validation + uses: "hacs/action@main" + with: + category: "integration" + ignore: brands + - uses: home-assistant/actions/hassfest@master diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 333e057..718c18e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,63 +1,13 @@ --- - repos: - - repo: https://github.com/asottile/pyupgrade - rev: v2.7.2 - hooks: - - id: pyupgrade - args: [--py38-plus] - - repo: https://github.com/psf/black - rev: 21.7b0 - hooks: - - id: black - args: - - --safe - - --quiet - files: ^((homeassistant|script|tests)/.+)?[^/]+\.py$ - - repo: https://github.com/codespell-project/codespell - rev: v2.0.0 - hooks: - - id: codespell - args: - - --ignore-words-list=hass,alot,datas,dof,dur,ether,farenheit,hist,iff,ines,ist,lightsensor,mut,nd,pres,referer,ser,serie,te,technik,ue,uint,visability,wan,wanna,withing,iam,incomfort - - --skip="./.*,*.csv,*.json" - - --quiet-level=2 - exclude_types: [csv, json] - exclude: ^tests/fixtures/ - - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.4 - hooks: - - id: flake8 - additional_dependencies: - - flake8-docstrings==1.5.0 - - pydocstyle==5.1.1 - files: ^(homeassistant|script|tests)/.+\.py$ - - repo: https://github.com/PyCQA/bandit - rev: 1.7.0 - hooks: - - id: bandit - args: - - --quiet - - --format=custom - - --configfile=tests/bandit.yaml - files: ^(homeassistant|script|tests)/.+\.py$ - - repo: https://github.com/PyCQA/isort - rev: 5.5.3 - hooks: - - id: isort - repo: https://github.com/pre-commit/pre-commit-hooks rev: v3.2.0 hooks: - - id: check-executables-have-shebangs - stages: [manual] - - id: check-json - exclude: (.vscode|.devcontainer) - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - id: check-added-large-files - - repo: https://github.com/prettier/prettier - rev: 2.0.4 + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v2.2.1 hooks: - id: prettier - stages: [manual] diff --git a/.vscode/launch.json b/.vscode/launch.json index b896aae..2aefd8f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,12 +1,12 @@ { - "configurations": [ - { - "name": "Pre-commit", - "request": "launch", - "type": "python", - "cwd": "${workspaceFolder}", - "program": "${workspaceFolder}/venv/Scripts/pre-commit.exe", - "args": ["run", "--all-files", "--show-diff-on-failure", "--color=always"] - } - ] + "configurations": [ + { + "name": "Pre-commit", + "request": "launch", + "type": "python", + "cwd": "${workspaceFolder}", + "program": "${workspaceFolder}/venv/Scripts/pre-commit.exe", + "args": ["run", "--all-files", "--show-diff-on-failure", "--color=always"] + } + ] } diff --git a/CHANGELOG.md b/CHANGELOG.md index e2e9f35..2a11762 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Removed entity / device delete upon restarting HA - + ## 1.0.5 - Added support for long term statistics @@ -81,14 +82,14 @@ - Fix disabled entities still being triggered for updates [\#52](https://github.com/elad-bar/ha-hpprinter/issues/52) - Fix image drum OPC name [\#51](https://github.com/elad-bar/ha-hpprinter/issues/51) -- Fix Sensor 'status' stays on after power off [\#45](https://github.com/elad-bar/ha-hpprinter/issues/45) +- Fix Sensor 'status' stays on after power off [\#45](https://github.com/elad-bar/ha-hpprinter/issues/45) ## 2020-04-26 **Fixed bugs:** - Fix disabled entities are getting enabled after periodic update (update interval) -- Fix offline printer is not updating entities correctly and after restart [\#45](https://github.com/elad-bar/ha-hpprinter/issues/45) [\#47](https://github.com/elad-bar/ha-hpprinter/issues/47) +- Fix offline printer is not updating entities correctly and after restart [\#45](https://github.com/elad-bar/ha-hpprinter/issues/45) [\#47](https://github.com/elad-bar/ha-hpprinter/issues/47) ## 2020-04-24 #6 @@ -130,7 +131,7 @@ **Implemented enhancements:** - Added changelog -- Added ability to configure update entities interval in seconds (Integrations -> Integration Name -> Options) [\#31](https://github.com/elad-bar/ha-hpprinter/issues/31) +- Added ability to configure update entities interval in seconds (Integrations -> Integration Name -> Options) [\#31](https://github.com/elad-bar/ha-hpprinter/issues/31) - Added validation to add new integration, display error in case printer is unreachable or unsupported [\#15](https://github.com/elad-bar/ha-hpprinter/issues/15) [\#11](https://github.com/elad-bar/ha-hpprinter/issues/11) - Moved code to new file structure - More logs added for easier debugging diff --git a/README.md b/README.md index 2b240ed..e572680 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # HP Printer integration for Home Assistant + ### Description + Configuration support multiple HP Printer devices through Configuration -> Integrations [Changelog](https://github.com/elad-bar/ha-hpprinter/blob/master/CHANGELOG.md) @@ -9,23 +11,26 @@ Configuration support multiple HP Printer devices through Configuration -> Integ Look for "HP Printers Integration" and install #### Requirements -* HP Printer supporting XML API + +- HP Printer supporting XML API to check printer's compatibility to the component try to get to the printer's XML API (replace placeholder with real IP / Hostname): `http://{IP}//DevMgmt/ProductStatusDyn.xml` #### Basic configuration -* Configuration should be done via Configuration -> Integrations. -* In case you are already using that integration with YAML Configuration - please remove it -* Integration supports **multiple** devices -* In the setup form, the following details are mandatory: - * Name - Unique - * Host (or IP) -* Upon submitting the form of creating an integration, a request to the printer will take place and will cause failure in case: - * Unsupported API - * Invalid server details - when cannot reach host + +- Configuration should be done via Configuration -> Integrations. +- In case you are already using that integration with YAML Configuration - please remove it +- Integration supports **multiple** devices +- In the setup form, the following details are mandatory: + - Name - Unique + - Host (or IP) +- Upon submitting the form of creating an integration, a request to the printer will take place and will cause failure in case: + - Unsupported API + - Invalid server details - when cannot reach host #### Settings for Monitoring interfaces, devices, tracked devices and update interval -*Configuration -> Integrations -> {Integration} -> Options*
+ +_Configuration -> Integrations -> {Integration} -> Options_
``` Name - Unique @@ -36,6 +41,7 @@ Should store responses?: Check-box, saves XML and JSON files for debugging purpo ``` ###### Log Level's drop-down + New feature to set the log level for the component without need to set log_level in `customization:` and restart or call manually `logger.set_level` and loose it after restart. Upon startup or integration's option update, based on the value chosen, the component will make a service call to `logger.set_level` for that component with the desired value, @@ -43,23 +49,28 @@ Upon startup or integration's option update, based on the value chosen, the comp In case `Default` option is chosen, flow will skip calling the service, after changing from any other option to `Default`, it will not take place automatically, only after restart ###### Store responses -Stores the XML and JSON of each request and final JSON to files, Path in CONFIG_PATH/*, + +Stores the XML and JSON of each request and final JSON to files, Path in CONFIG_PATH/\*, Files that will be generated (Prefix to the file is name of the integration): - - ProductUsageDyn.XML - Raw XML from HP Printer of Usage Details - - ProductUsageDyn.json - JSON based on the Raw XML of Usage Details after transformed by the component - - ConsumableConfigDyn.XML - Raw XML from HP Printer of consumable details - - ConsumableConfigDyn.json - JSON based on the Raw XML of consumable details after transformed by the component - - ProductConfigDyn.XML - Raw XML from HP Printer of Config Details - - ProductConfigDyn.json - JSON based on the Raw XML of Config Details after transformed by the component - - Final.json - JSON based on the 2 JSONs above, merged into simpler data structure for the HA to create sensor based on + +- ProductUsageDyn.XML - Raw XML from HP Printer of Usage Details +- ProductUsageDyn.json - JSON based on the Raw XML of Usage Details after transformed by the component +- ConsumableConfigDyn.XML - Raw XML from HP Printer of consumable details +- ConsumableConfigDyn.json - JSON based on the Raw XML of consumable details after transformed by the component +- ProductConfigDyn.XML - Raw XML from HP Printer of Config Details +- ProductConfigDyn.json - JSON based on the Raw XML of Config Details after transformed by the component +- Final.json - JSON based on the 2 JSONs above, merged into simpler data structure for the HA to create sensor based on ## Components: + #### Device status - Binary Sensor + ``` State: connected? ``` #### Printer details - Sensor + ``` State: # of pages printed Attributes: @@ -70,6 +81,7 @@ Attributes: ``` #### Scanner details - Sensor (For AIO only) + ``` State: # of pages scanned Attributes: @@ -81,6 +93,7 @@ Attributes: ``` #### Cartridges details - Sensor (Per cartridge) + ``` State: Remaining level % Attributes: diff --git a/custom_components/hpprinter/manifest.json b/custom_components/hpprinter/manifest.json index 5b9f5b0..c8617ed 100644 --- a/custom_components/hpprinter/manifest.json +++ b/custom_components/hpprinter/manifest.json @@ -1,13 +1,13 @@ { - "domain": "hpprinter", - "name": "HP Printer", - "documentation": "https://github.com/elad-bar/ha-hpprinter", - "issue_tracker": "https://github.com/elad-bar/ha-hpprinter/issues", - "codeowners": ["@elad-bar"], - "dependencies": [], - "after_dependencies": [ "logger" ], - "requirements": ["xmltodict==0.12.0"], - "config_flow": true, - "version": "1.0.7", - "iot_class": "local_polling" + "domain": "hpprinter", + "name": "HP Printer", + "documentation": "https://github.com/elad-bar/ha-hpprinter", + "issue_tracker": "https://github.com/elad-bar/ha-hpprinter/issues", + "codeowners": ["@elad-bar"], + "dependencies": [], + "after_dependencies": ["logger"], + "requirements": ["xmltodict==0.12.0"], + "config_flow": true, + "version": "1.0.7", + "iot_class": "local_polling" } diff --git a/custom_components/hpprinter/strings.json b/custom_components/hpprinter/strings.json index 01d9f5c..9e1beba 100644 --- a/custom_components/hpprinter/strings.json +++ b/custom_components/hpprinter/strings.json @@ -18,19 +18,19 @@ } }, "options": { - "step": { - "hp_printer_additional_settings": { - "title": "Options for HP Printer.", - "description": "Define additional settings for HP Printer integration", - "data": { - "host": "Host", - "name": "Name", - "update_interval": "Update interval (Seconds)", - "log_level": "Log level", - "store_data": "Should store responses?" - } - } - }, + "step": { + "hp_printer_additional_settings": { + "title": "Options for HP Printer.", + "description": "Define additional settings for HP Printer integration", + "data": { + "host": "Host", + "name": "Name", + "update_interval": "Update interval (Seconds)", + "log_level": "Log level", + "store_data": "Should store responses?" + } + } + }, "error": { "error_400": "Invalid server details, please try manually access to `http://{IP}//DevMgmt/ProductStatusDyn.xml` (Replace placeholder with IP or Hostname), in case it's accessible, please report the issue with logs", "error_404": "Unsupported API", diff --git a/custom_components/hpprinter/translations/dk.json b/custom_components/hpprinter/translations/dk.json index 8f714a8..09cb76b 100644 --- a/custom_components/hpprinter/translations/dk.json +++ b/custom_components/hpprinter/translations/dk.json @@ -18,19 +18,19 @@ } }, "options": { - "step": { - "hp_printer_additional_settings": { - "title": "Indstillinger for HP Printer.", - "description": "Definer yderligere indstillinger for HP Printer integration ", - "data": { - "host": "Vært", - "name": "Navn", - "update_interval": "Opdateringsinterval (sekunder)", - "log_level": "Log level", - "store_data": "Skal svar gemmes?" - } - } - }, + "step": { + "hp_printer_additional_settings": { + "title": "Indstillinger for HP Printer.", + "description": "Definer yderligere indstillinger for HP Printer integration ", + "data": { + "host": "Vært", + "name": "Navn", + "update_interval": "Opdateringsinterval (sekunder)", + "log_level": "Log level", + "store_data": "Skal svar gemmes?" + } + } + }, "error": { "error_400": "Ugyldige serveroplysninger, prøv venligst manuelt at få adgang til `http://{IP}//DevMgmt/ProductStatusDyn.xml` (Erstat pladsholder med IP eller værtsnavn ), hvis det er tilgængeligt, bedes du rapportere problemet med logfiler", "error_404": "Ikke understøttet API", diff --git a/custom_components/hpprinter/translations/en.json b/custom_components/hpprinter/translations/en.json index 01d9f5c..9e1beba 100644 --- a/custom_components/hpprinter/translations/en.json +++ b/custom_components/hpprinter/translations/en.json @@ -18,19 +18,19 @@ } }, "options": { - "step": { - "hp_printer_additional_settings": { - "title": "Options for HP Printer.", - "description": "Define additional settings for HP Printer integration", - "data": { - "host": "Host", - "name": "Name", - "update_interval": "Update interval (Seconds)", - "log_level": "Log level", - "store_data": "Should store responses?" - } - } - }, + "step": { + "hp_printer_additional_settings": { + "title": "Options for HP Printer.", + "description": "Define additional settings for HP Printer integration", + "data": { + "host": "Host", + "name": "Name", + "update_interval": "Update interval (Seconds)", + "log_level": "Log level", + "store_data": "Should store responses?" + } + } + }, "error": { "error_400": "Invalid server details, please try manually access to `http://{IP}//DevMgmt/ProductStatusDyn.xml` (Replace placeholder with IP or Hostname), in case it's accessible, please report the issue with logs", "error_404": "Unsupported API", diff --git a/custom_components/hpprinter/translations/es.json b/custom_components/hpprinter/translations/es.json index 9f5a7b7..d1ba5a0 100644 --- a/custom_components/hpprinter/translations/es.json +++ b/custom_components/hpprinter/translations/es.json @@ -18,23 +18,23 @@ } }, "options": { - "step": { - "hp_printer_additional_settings": { - "title": "Opciones para la impresora HP.", - "description": "Definir configuraciones adicionales para la integración de la impresora HP", - "data": { - "host": "Host", - "name": "Nombre", - "update_interval": "Intervalo de actualización (segundos)", - "log_level": "Nivel del registro", - "store_data": "Debería almacenar respuestas?" - } - } - }, + "step": { + "hp_printer_additional_settings": { + "title": "Opciones para la impresora HP.", + "description": "Definir configuraciones adicionales para la integración de la impresora HP", + "data": { + "host": "Host", + "name": "Nombre", + "update_interval": "Intervalo de actualización (segundos)", + "log_level": "Nivel del registro", + "store_data": "Debería almacenar respuestas?" + } + } + }, "error": { "error_400": "Los detalles del servidor no son válidos", "error_404": "API no compatible", - "already_configured": "La integración de la impresora HP ({name}) ya está configurada" + "already_configured": "La integración de la impresora HP ({name}) ya está configurada" } } } diff --git a/custom_components/hpprinter/translations/nb.json b/custom_components/hpprinter/translations/nb.json index 43411e6..ed17b4e 100644 --- a/custom_components/hpprinter/translations/nb.json +++ b/custom_components/hpprinter/translations/nb.json @@ -1,4 +1,3 @@ - { "config": { "step": { @@ -19,19 +18,19 @@ } }, "options": { - "step": { - "hp_printer_additional_settings": { - "title": "Alternativer for HP-skriver.", - "description": "Definer tilleggsinnstillinger for HP-skriverintegrasjon", - "data": { - "host": "Vert", - "name": "Navn", - "update_interval": "Oppdateringsintervall (sekunder)", - "log_level": "Loggnivå", - "store_data": "Bør lagre svar?" - } - } - }, + "step": { + "hp_printer_additional_settings": { + "title": "Alternativer for HP-skriver.", + "description": "Definer tilleggsinnstillinger for HP-skriverintegrasjon", + "data": { + "host": "Vert", + "name": "Navn", + "update_interval": "Oppdateringsintervall (sekunder)", + "log_level": "Loggnivå", + "store_data": "Bør lagre svar?" + } + } + }, "error": { "error_400": "Ugyldige serveropplysninger. Prøv manuelt å få tilgang ti `http://{IP}//DevMgmt/ProductStatusDyn.xml` (Erstatt plassholder med IP eller vertsnavn), hvis det er tilgjengelig, vennligst rapporter problemet med logger", "error_404": "API støttes ikke", diff --git a/custom_components/hpprinter/translations/pl.json b/custom_components/hpprinter/translations/pl.json index 96e391a..4434588 100644 --- a/custom_components/hpprinter/translations/pl.json +++ b/custom_components/hpprinter/translations/pl.json @@ -18,19 +18,19 @@ } }, "options": { - "step": { - "hp_printer_additional_settings": { - "title": "Opcje dla drukarki HP.", - "description": "Zdefiniuj dodatkowe ustawienia dla integracji drukarki HP", - "data": { - "host": "Host lub IP", - "name": "Nazwa", - "update_interval": "Interwał aktualizacji (sekundy)", - "log_level": "Poziom logowania", - "store_data": "Czy należy przechowywać odpowiedzi?" - } - } - }, + "step": { + "hp_printer_additional_settings": { + "title": "Opcje dla drukarki HP.", + "description": "Zdefiniuj dodatkowe ustawienia dla integracji drukarki HP", + "data": { + "host": "Host lub IP", + "name": "Nazwa", + "update_interval": "Interwał aktualizacji (sekundy)", + "log_level": "Poziom logowania", + "store_data": "Czy należy przechowywać odpowiedzi?" + } + } + }, "error": { "error_400": "Nieprawidłowe dane serwera, spróbuj ręcznie uzyskać otworzyć `http://{IP}//DevMgmt/ProductStatusDyn.xml` (Zamień tekst zastępczy na IP lub nazwę hosta), jeśli to możliwe - zgłoś problem wraz z logami.", "error_404": "Niewspierane API", diff --git a/custom_components/hpprinter/translations/pt-BR.json b/custom_components/hpprinter/translations/pt-BR.json index 7048437..035499e 100644 --- a/custom_components/hpprinter/translations/pt-BR.json +++ b/custom_components/hpprinter/translations/pt-BR.json @@ -18,19 +18,19 @@ } }, "options": { - "step": { - "hp_printer_additional_settings": { - "title": "Opções para HP Printer.", - "description": "Defina configurações adicionais para a integração HP Printer", - "data": { - "host": "Host", - "name": "Nome", - "update_interval": "Intervalo de atualização (segundos)", - "log_level": "Nível de registro", - "store_data": "Deve armazenar respostas?" - } - } - }, + "step": { + "hp_printer_additional_settings": { + "title": "Opções para HP Printer.", + "description": "Defina configurações adicionais para a integração HP Printer", + "data": { + "host": "Host", + "name": "Nome", + "update_interval": "Intervalo de atualização (segundos)", + "log_level": "Nível de registro", + "store_data": "Deve armazenar respostas?" + } + } + }, "error": { "error_400": "Detalhes do servidor inválidos, tente acessar manualmente `http://{IP}//DevMgmt/ProductStatusDyn.xml` (Substituir o marcador de posição por IP ou Hostname), caso esteja acessível, informe o problema com os logs", "error_404": "API sem suporte", diff --git a/info.md b/info.md index 2b240ed..e572680 100644 --- a/info.md +++ b/info.md @@ -1,5 +1,7 @@ # HP Printer integration for Home Assistant + ### Description + Configuration support multiple HP Printer devices through Configuration -> Integrations [Changelog](https://github.com/elad-bar/ha-hpprinter/blob/master/CHANGELOG.md) @@ -9,23 +11,26 @@ Configuration support multiple HP Printer devices through Configuration -> Integ Look for "HP Printers Integration" and install #### Requirements -* HP Printer supporting XML API + +- HP Printer supporting XML API to check printer's compatibility to the component try to get to the printer's XML API (replace placeholder with real IP / Hostname): `http://{IP}//DevMgmt/ProductStatusDyn.xml` #### Basic configuration -* Configuration should be done via Configuration -> Integrations. -* In case you are already using that integration with YAML Configuration - please remove it -* Integration supports **multiple** devices -* In the setup form, the following details are mandatory: - * Name - Unique - * Host (or IP) -* Upon submitting the form of creating an integration, a request to the printer will take place and will cause failure in case: - * Unsupported API - * Invalid server details - when cannot reach host + +- Configuration should be done via Configuration -> Integrations. +- In case you are already using that integration with YAML Configuration - please remove it +- Integration supports **multiple** devices +- In the setup form, the following details are mandatory: + - Name - Unique + - Host (or IP) +- Upon submitting the form of creating an integration, a request to the printer will take place and will cause failure in case: + - Unsupported API + - Invalid server details - when cannot reach host #### Settings for Monitoring interfaces, devices, tracked devices and update interval -*Configuration -> Integrations -> {Integration} -> Options*
+ +_Configuration -> Integrations -> {Integration} -> Options_
``` Name - Unique @@ -36,6 +41,7 @@ Should store responses?: Check-box, saves XML and JSON files for debugging purpo ``` ###### Log Level's drop-down + New feature to set the log level for the component without need to set log_level in `customization:` and restart or call manually `logger.set_level` and loose it after restart. Upon startup or integration's option update, based on the value chosen, the component will make a service call to `logger.set_level` for that component with the desired value, @@ -43,23 +49,28 @@ Upon startup or integration's option update, based on the value chosen, the comp In case `Default` option is chosen, flow will skip calling the service, after changing from any other option to `Default`, it will not take place automatically, only after restart ###### Store responses -Stores the XML and JSON of each request and final JSON to files, Path in CONFIG_PATH/*, + +Stores the XML and JSON of each request and final JSON to files, Path in CONFIG_PATH/\*, Files that will be generated (Prefix to the file is name of the integration): - - ProductUsageDyn.XML - Raw XML from HP Printer of Usage Details - - ProductUsageDyn.json - JSON based on the Raw XML of Usage Details after transformed by the component - - ConsumableConfigDyn.XML - Raw XML from HP Printer of consumable details - - ConsumableConfigDyn.json - JSON based on the Raw XML of consumable details after transformed by the component - - ProductConfigDyn.XML - Raw XML from HP Printer of Config Details - - ProductConfigDyn.json - JSON based on the Raw XML of Config Details after transformed by the component - - Final.json - JSON based on the 2 JSONs above, merged into simpler data structure for the HA to create sensor based on + +- ProductUsageDyn.XML - Raw XML from HP Printer of Usage Details +- ProductUsageDyn.json - JSON based on the Raw XML of Usage Details after transformed by the component +- ConsumableConfigDyn.XML - Raw XML from HP Printer of consumable details +- ConsumableConfigDyn.json - JSON based on the Raw XML of consumable details after transformed by the component +- ProductConfigDyn.XML - Raw XML from HP Printer of Config Details +- ProductConfigDyn.json - JSON based on the Raw XML of Config Details after transformed by the component +- Final.json - JSON based on the 2 JSONs above, merged into simpler data structure for the HA to create sensor based on ## Components: + #### Device status - Binary Sensor + ``` State: connected? ``` #### Printer details - Sensor + ``` State: # of pages printed Attributes: @@ -70,6 +81,7 @@ Attributes: ``` #### Scanner details - Sensor (For AIO only) + ``` State: # of pages scanned Attributes: @@ -81,6 +93,7 @@ Attributes: ``` #### Cartridges details - Sensor (Per cartridge) + ``` State: Remaining level % Attributes: