Skip to content

Commit

Permalink
Merge pull request #69 from Flameeyes/main
Browse files Browse the repository at this point in the history
Follow current Home Assistant best practices
  • Loading branch information
Kakise authored Nov 16, 2021
2 parents 7b0d18e + 8ab8516 commit 91a95a6
Show file tree
Hide file tree
Showing 16 changed files with 483 additions and 680 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/hassfest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Validate with hassfest

on:
push:
pull_request:
schedule:
- cron: "0 0 * * *"

jobs:
validate:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- uses: home-assistant/actions/hassfest@master
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.7.2
rev: v2.29.0
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/psf/black
rev: 20.8b1
rev: 21.10b0
hooks:
- id: black
args:
- --safe
- --quiet
files: ^((custom_components|tests)/.+)?[^/]+\.py$
- repo: https://github.com/codespell-project/codespell
rev: v2.0.0
rev: v2.1.0
hooks:
- id: codespell
args:
Expand All @@ -23,15 +23,15 @@ repos:
exclude_types: [csv, json]
exclude: ^tests/fixtures/
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies:
- flake8-docstrings==1.5.0
- pydocstyle==5.1.1
files: ^(custom_components|tests)/.+\.py$
- repo: https://github.com/PyCQA/bandit
rev: 1.7.0
rev: 1.7.1
hooks:
- id: bandit
args:
Expand All @@ -40,27 +40,27 @@ repos:
- --configfile=bandit.yaml
files: ^(custom_components|tests)/.+\.py$
- repo: https://github.com/PyCQA/isort
rev: 5.5.3
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v4.0.1
hooks:
- id: check-executables-have-shebangs
stages: [manual]
- id: check-json
exclude: (.vscode|.devcontainer)
- repo: https://github.com/prettier/prettier
rev: 2.0.4
rev: 2.4.1
hooks:
- id: prettier
stages: [manual]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.800
rev: v0.910-1
hooks:
- id: mypy
files: custom_components/.+\.py
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.24.2
rev: v1.26.3
hooks:
- id: yamllint
6 changes: 4 additions & 2 deletions custom_components/dyson_local/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
def _async_get_platforms(device: DysonDevice) -> List[str]:
if isinstance(device, Dyson360Eye) or isinstance(device, Dyson360Heurist):
return ["binary_sensor", "sensor", "vacuum"]
platforms = ["air_quality", "fan", "sensor", "switch"]
if isinstance(device, DysonPureHotCool) or isinstance(device, DysonPureHotCoolLink):
platforms = ["fan", "select", "sensor", "switch"]
if isinstance(device, DysonPureHotCool):
platforms.append("climate")
if isinstance(device, DysonPureHotCoolLink):
platforms.extend(["binary_sensor", "climate"])
if isinstance(device, DysonPureHumidifyCool):
platforms.append("humidifier")
return platforms
Expand Down
105 changes: 0 additions & 105 deletions custom_components/dyson_local/air_quality.py

This file was deleted.

43 changes: 39 additions & 4 deletions custom_components/dyson_local/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

from typing import Callable

from libdyson import Dyson360Heurist
from libdyson import Dyson360Eye, Dyson360Heurist, DysonPureHotCoolLink

from homeassistant.components.binary_sensor import (
DEVICE_CLASS_BATTERY_CHARGING,
BinarySensorEntity,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_NAME
from homeassistant.const import CONF_NAME, ENTITY_CATEGORY_DIAGNOSTIC
from homeassistant.core import HomeAssistant

from . import DysonEntity
Expand All @@ -24,15 +24,26 @@ async def async_setup_entry(
"""Set up Dyson binary sensor from a config entry."""
device = hass.data[DOMAIN][DATA_DEVICES][config_entry.entry_id]
name = config_entry.data[CONF_NAME]
entities = [DysonVacuumBatteryChargingSensor(device, name)]
entities = []
if isinstance(device, Dyson360Eye):
entities.append(DysonVacuumBatteryChargingSensor(device, name))
if isinstance(device, Dyson360Heurist):
entities.append(Dyson360HeuristBinFullSensor(device, name))
entities.extend(
[
DysonVacuumBatteryChargingSensor(device, name),
Dyson360HeuristBinFullSensor(device, name),
]
)
if isinstance(device, DysonPureHotCoolLink):
entities.extend([DysonPureHotCoolLinkTiltSensor(device, name)])
async_add_entities(entities)


class DysonVacuumBatteryChargingSensor(DysonEntity, BinarySensorEntity):
"""Dyson vacuum battery charging sensor."""

_attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC

@property
def is_on(self) -> bool:
"""Return if the sensor is on."""
Expand All @@ -57,6 +68,8 @@ def sub_unique_id(self):
class Dyson360HeuristBinFullSensor(DysonEntity, BinarySensorEntity):
"""Dyson 360 Heurist bin full sensor."""

_attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC

@property
def is_on(self) -> bool:
"""Return if the sensor is on."""
Expand All @@ -76,3 +89,25 @@ def sub_name(self) -> str:
def sub_unique_id(self):
"""Return the sensor's unique id."""
return "bin_full"


class DysonPureHotCoolLinkTiltSensor(DysonEntity, BinarySensorEntity):
"""Dyson Pure Hot+Cool Link tilt sensor."""

_attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC
_attr_icon = "mdi:angle-acute"

@property
def is_on(self) -> bool:
"""Return if the sensor is on."""
return self._device.tilt

@property
def sub_name(self) -> str:
"""Return the name of the sensor."""
return "Tilt"

@property
def sub_unique_id(self):
"""Return the sensor's unique id."""
return "tilt"
Loading

0 comments on commit 91a95a6

Please sign in to comment.