Skip to content

Commit

Permalink
Merge pull request #100 from elad-bar/breaking-changes-ha-2024-01
Browse files Browse the repository at this point in the history
Adjust code to HA 2024.1.0
  • Loading branch information
elad-bar authored Dec 29, 2023
2 parents cb0092d + 4c65453 commit beb06ab
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 89 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/constraints.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pip==20.3.3
pre-commit==2.9.3
nox==2020.12.31
pip==22.2.2
pre-commit==2.20.0
nox==2022.8.7
5 changes: 2 additions & 3 deletions .github/workflows/hassfest.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---

name: Validate with hassfest

# yamllint disable-line rule:truthy
on:
push:
pull_request:
Expand All @@ -12,5 +11,5 @@ jobs:
validate:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- uses: "actions/checkout@v3.1.0"
- uses: home-assistant/actions/hassfest@master
41 changes: 7 additions & 34 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -1,42 +1,15 @@
name: Linting
name: pre-commit

# yamllint disable-line rule:truthy
on:
push:
branches:
- main
- master
- dev
pull_request:
push:
branches: [master]

jobs:
pre-commit:
runs-on: ubuntu-latest
name: pre-commit
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
python-version: "3.9"
- run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip install --constraint=.github/workflows/constraints.txt pre-commit
- name: Compute cache key prefix
if: matrix.os != 'windows-latest'
id: cache_key_prefix
shell: python
run: |
import hashlib
import sys
python = "py{}.{}".format(*sys.version_info[:2])
payload = sys.version.encode() + sys.executable.encode()
digest = hashlib.sha256(payload).hexdigest()
result = "${{ runner.os }}-{}-{}-pre-commit".format(python, digest)
print("::set-output name=result::{}".format(result))
- uses: actions/[email protected]
if: matrix.os != 'windows-latest'
with:
path: ~/.cache/pre-commit
key: ${{ steps.cache_key_prefix.outputs.result }}-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
${{ steps.cache_key_prefix.outputs.result }}-
- run: pre-commit run --all-files --show-diff-on-failure --color=always
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
56 changes: 33 additions & 23 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,63 +1,73 @@
---

repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.32.1
rev: v3.15.0
hooks:
- id: pyupgrade
args: [ --py39 ]
args: [--py39-plus]
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.12.1
hooks:
- id: black
args:
- --safe
- --quiet
files: ^((homeassistant|script|tests)/.+)?[^/]+\.py$
files: ^((custom_components)/.+)?[^/]+\.py$
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
rev: v2.2.6
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
- repo: https://github.com/PyCQA/autoflake
rev: v2.2.1
hooks:
- id: autoflake
args:
- --in-place
- --remove-all-unused-imports
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
- flake8-docstrings==1.5.0
- pydocstyle==5.1.1
files: ^(homeassistant|script|tests)/.+\.py$
- pycodestyle>=2.10.0
- pyflakes>=3.0.1
# - flake8-docstrings==1.6.0
# - pydocstyle==6.2.3
- flake8-comprehensions>=3.10.1
- flake8-noqa>=1.3.0
- mccabe>=0.7.0
files: ^(custom_components)/.+\.py$
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
rev: 1.7.6
hooks:
- id: bandit
args:
- --quiet
- --format=custom
- --configfile=tests/bandit.yaml
files: ^(homeassistant|script|tests)/.+\.py$
- --configfile=bandit.yaml
files: ^(custom_components)/.+\.py$
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v4.5.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/adrienverge/yamllint.git
rev: v1.33.0
hooks:
- id: yamllint
exclude: (.yamllint)
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.6.1
rev: v3.0.3
hooks:
- id: prettier
stages: [manual]
61 changes: 61 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
ignore: |
azure-*.yml
rules:
braces:
level: error
min-spaces-inside: 0
max-spaces-inside: 1
min-spaces-inside-empty: -1
max-spaces-inside-empty: -1
brackets:
level: error
min-spaces-inside: 0
max-spaces-inside: 0
min-spaces-inside-empty: -1
max-spaces-inside-empty: -1
colons:
level: error
max-spaces-before: 0
max-spaces-after: 1
commas:
level: error
max-spaces-before: 0
min-spaces-after: 1
max-spaces-after: 1
comments:
level: error
require-starting-space: true
min-spaces-from-content: 2
comments-indentation:
level: error
document-end:
level: error
present: false
document-start:
level: error
present: false
empty-lines:
level: error
max: 1
max-start: 0
max-end: 1
hyphens:
level: error
max-spaces-after: 1
indentation:
level: error
spaces: 2
indent-sequences: true
check-multi-line-strings: false
key-duplicates:
level: error
line-length: disable
new-line-at-end-of-file:
level: error
new-lines:
level: error
type: unix
trailing-spaces:
level: error
truthy:
level: error
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 1.0.9

_Minimum HA Version: 2024.1.0_

- Adjust code to HA 2024.1.0
- Update pre-commit packages

## 1.0.8

- Device and Entity registry - `async_get_registry` is deprecated, change to `async_get`
Expand Down
20 changes: 20 additions & 0 deletions bandit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# https://bandit.readthedocs.io/en/latest/config.html

tests:
- B103
- B108
- B306
- B307
- B313
- B314
- B315
- B316
- B317
- B318
- B319
- B320
- B601
- B602
- B604
- B608
- B609
5 changes: 3 additions & 2 deletions custom_components/hpprinter/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ async def async_step_import(self, info):
_LOGGER.debug(f"Starting async_step_import of {DOMAIN}")

return self.async_create_entry(
title="HPPrinter (import from configuration.yaml)", data=info,
title="HPPrinter (import from configuration.yaml)",
data=info,
)


Expand Down Expand Up @@ -103,7 +104,7 @@ async def async_step_hp_printer_additional_settings(self, user_input=None):
)

except LoginError as lex:
_LOGGER.warning(f"Cannot complete login")
_LOGGER.warning("Cannot complete login")

errors = lex.errors

Expand Down
6 changes: 3 additions & 3 deletions custom_components/hpprinter/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

def clear_ha(hass: HomeAssistant, name):
if DATA_HP_PRINTER not in hass.data:
hass.data[DATA_HP_PRINTER] = dict()
hass.data[DATA_HP_PRINTER] = {}

del hass.data[DATA_HP_PRINTER][name]


def get_ha(hass: HomeAssistant, host):
ha_data = hass.data.get(DATA_HP_PRINTER, dict())
ha_data = hass.data.get(DATA_HP_PRINTER, {})
ha = ha_data.get(host)

return ha
Expand All @@ -28,7 +28,7 @@ def get_ha(hass: HomeAssistant, host):
async def async_set_ha(hass: HomeAssistant, name, entry: ConfigEntry):
try:
if DATA_HP_PRINTER not in hass.data:
hass.data[DATA_HP_PRINTER] = dict()
hass.data[DATA_HP_PRINTER] = {}

instance = HPPrinterHomeAssistant(hass)

Expand Down
11 changes: 2 additions & 9 deletions custom_components/hpprinter/helpers/const.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
from homeassistant.components.binary_sensor import (
DOMAIN as DOMAIN_BINARY_SENSOR,
BinarySensorDeviceClass,
)
from homeassistant.components.sensor import (
DOMAIN as DOMAIN_SENSOR,
SensorDeviceClass,
SensorStateClass,
)
from homeassistant.components.binary_sensor import DOMAIN as DOMAIN_BINARY_SENSOR
from homeassistant.components.sensor import DOMAIN as DOMAIN_SENSOR

MANUFACTURER = "HP"
DEFAULT_NAME = "HP Printer"
Expand Down
14 changes: 8 additions & 6 deletions custom_components/hpprinter/managers/config_flow_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,14 @@ def update_data(self, data: dict, update_entry: bool = False):
self._update_entry()

def _update_entry(self):
entry = ConfigEntry(version=0,
domain="",
title="",
data=self.data,
source="",
options=self.options)
entry = ConfigEntry(
version=0,
domain="",
title="",
data=self.data,
source="",
options=self.options,
)

self.config_manager.update(entry)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/hpprinter/managers/entity_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import sys
from typing import Dict, List, Optional
from typing import Optional

from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_registry import EntityRegistry
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hpprinter/managers/home_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async def delete_entity(self, domain, name):

async def dispatch_all(self):
if not self._is_initialized:
_LOGGER.info(f"NOT INITIALIZED - Failed discovering components")
_LOGGER.info("NOT INITIALIZED - Failed discovering components")
return

for domain in SIGNALS:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hpprinter/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"after_dependencies": ["logger"],
"requirements": ["xmltodict==0.12.0"],
"config_flow": true,
"version": "1.0.8",
"version": "1.0.9",
"iot_class": "local_polling"
}
1 change: 0 additions & 1 deletion custom_components/hpprinter/models/base_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ async def async_setup_base_entry(
domain: str,
component: Callable[[HomeAssistant, Any, EntityData], Any],
):

"""Set up HP Printer based off an entry."""
_LOGGER.debug(f"Starting async_setup_entry {domain}")

Expand Down
2 changes: 1 addition & 1 deletion custom_components/hpprinter/models/entity_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __repr__(self):
ENTITY_DISABLED: self.disabled,
ENTITY_BINARY_SENSOR_DEVICE_CLASS: self.binary_sensor_device_class,
ENTITY_SENSOR_DEVICE_CLASS: self.sensor_device_class,
ENTITY_SENSOR_STATE_CLASS: self.sensor_state_class
ENTITY_SENSOR_STATE_CLASS: self.sensor_state_class,
}

to_string = f"{obj}"
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "HP Printers Integration",
"iot_class": "Local Polling",
"homeassistant": "2021.12.0"
"homeassistant": "2024.1.0"
}

0 comments on commit beb06ab

Please sign in to comment.