Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecations for HA 2025.1 #86

Merged
merged 9 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions .flake8

This file was deleted.

20 changes: 0 additions & 20 deletions .github/workflows/pull_request_format.yaml

This file was deleted.

45 changes: 0 additions & 45 deletions .github/workflows/push_format.yaml

This file was deleted.

43 changes: 2 additions & 41 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
name: HACS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Validate
uses: hacs/action@main
with:
Expand All @@ -19,45 +19,6 @@ jobs:
name: Hassfest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Validate
uses: home-assistant/actions/hassfest@master
test_advice_flake8:
name: Test + advice with flake8
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Cache
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: pip-flake8
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
python -m pip install --upgrade flake8 wemake-python-styleguide
- name: Lint with flake8
run: |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
- name: Don't mind this
run: |
flake8 . --inline-quotes '"' --count --exit-zero --max-complexity=15 --max-line-length=90 --statistics --select=I,P,WPS305,C812,E203,W503,E800
- name: Docstrings
run: |
flake8 . --inline-quotes '"' --count --exit-zero --max-complexity=15 --max-line-length=90 --statistics --select=D,DAR
- name: Unused stuff
run: |
echo "Some stuff may not be used, but is used in commented out code."
echo "Make sure you check with the find command before you remove anything!"
flake8 . --inline-quotes '"' --count --exit-zero --max-complexity=15 --max-line-length=90 --statistics --select=F
echo "Some stuff may not be used, but is used in commented out code."
echo "Make sure you check with the find command before you remove anything!"
- name: General stats
run: |
flake8 . --inline-quotes '"' --count --exit-zero --max-complexity=15 --max-line-length=90 --statistics --ignore=I,P,WPS305,C812,E203,W503,E800,D,DAR,F
8 changes: 3 additions & 5 deletions custom_components/lutron_caseta_pro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ async def async_setup_bridge(hass, config, fname, bridge):
"""Initialize a bridge by loading its integration report."""
_LOGGER.debug("Setting up bridge using Integration Report %s", fname)

devices = await casetify.async_load_integration_report(fname)
devices = await hass.async_add_executor_job(casetify.load_integration_report, fname)

# Patch up device types from configuration.
# All other devices will be treated as lights.
Expand Down Expand Up @@ -200,7 +200,7 @@ async def async_setup_bridge(hass, config, fname, bridge):
for device_type in types:
component = device_type
_LOGGER.debug("Loading platform %s", component)
hass.async_add_job(
hass.async_create_task(
discovery.async_load_platform(
hass,
component,
Expand Down Expand Up @@ -416,9 +416,7 @@ def name(self):
def unique_id(self) -> str:
"""Return a unique ID."""
if self._mac is not None:
return "{}_{}_{}_{}".format(
DOMAIN, self._platform_domain, self._mac, self._integration
)
return f"{DOMAIN}_{self._platform_domain}_{self._mac}_{self._integration}"
return None


Expand Down
2 changes: 1 addition & 1 deletion custom_components/lutron_caseta_pro/casetify.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
_LOGGER = logging.getLogger(__name__)


async def async_load_integration_report(fname):
def load_integration_report(fname):
"""Process a JSON integration report and return a list of devices.

Each returned device will have an 'id', 'name', 'type' and optionally
Expand Down
46 changes: 35 additions & 11 deletions custom_components/lutron_caseta_pro/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@

Provides shade functionality for Home Assistant.
"""

import logging
from typing import Any

from homeassistant.components.cover import (
ATTR_POSITION,
DOMAIN,
SUPPORT_CLOSE,
SUPPORT_OPEN,
SUPPORT_SET_POSITION,
SUPPORT_STOP,
CoverEntity,
CoverEntityFeature,
)
from homeassistant.const import CONF_DEVICES, CONF_HOST, CONF_ID, CONF_MAC, CONF_NAME

Expand All @@ -25,6 +24,13 @@
CasetaEntity,
)

COVER_SUPPORT = (
CoverEntityFeature.CLOSE
| CoverEntityFeature.OPEN
| CoverEntityFeature.SET_POSITION
| CoverEntityFeature.STOP
)

_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -102,9 +108,14 @@ def current_cover_position(self):
"""Return current position of the cover."""
return self._position

async def async_open_cover(self, **kwargs):
async def async_open_cover(self, **kwargs: Any):
"""Open the cover."""
# Rasing must be used for STOP to work
_LOGGER.debug(
"Writing cover OUTPUT value: %d %d",
self._integration,
Caseta.Action.RAISING,
)
# Raising must be used for STOP to work
await self._data.caseta.write(
Caseta.OUTPUT, self._integration, Caseta.Action.RAISING, None
)
Expand All @@ -114,8 +125,13 @@ async def async_open_cover(self, **kwargs):
# will not do this on a Caseta.Action.RAISING
self.update_state(100)

async def async_close_cover(self, **kwargs):
async def async_close_cover(self, **kwargs: Any):
"""Close the cover."""
_LOGGER.debug(
"Writing cover OUTPUT value: %d %d",
self._integration,
Caseta.Action.LOWERING,
)
# Lowering must be used for STOP to work
await self._data.caseta.write(
Caseta.OUTPUT, self._integration, Caseta.Action.LOWERING, None
Expand All @@ -126,7 +142,7 @@ async def async_close_cover(self, **kwargs):
# will not do this on a Caseta.Action.LOWERING
self.update_state(0)

async def async_set_cover_position(self, **kwargs):
async def async_set_cover_position(self, **kwargs: Any):
"""Move the cover to a specific position."""
if ATTR_POSITION in kwargs:
position = kwargs[ATTR_POSITION]
Expand All @@ -139,18 +155,26 @@ async def async_set_cover_position(self, **kwargs):
"Tried to set cover position to greater than maximum value 100."
)
position = 100
_LOGGER.debug(
"Writing cover OUTPUT value: %d %d %d %d %d",
self._integration,
Caseta.Action.SET,
position,
0,
0,
)
# Parameters are Level, Fade, Delay
# Fade is ignored and Delay set to 0
await self._data.caseta.write(
Caseta.OUTPUT, self._integration, Caseta.Action.SET, position, 0, 0
)

@property
def supported_features(self):
def supported_features(self) -> CoverEntityFeature:
"""Flag supported features."""
return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP | SUPPORT_SET_POSITION
return COVER_SUPPORT

async def async_stop_cover(self, **kwargs):
async def async_stop_cover(self, **kwargs: Any):
"""Stop raising or lowering the shade."""
await self._data.caseta.write(
Caseta.OUTPUT, self._integration, Caseta.Action.STOP, None
Expand Down
23 changes: 14 additions & 9 deletions custom_components/lutron_caseta_pro/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

Provides fan functionality for Home Assistant.
"""

import logging
from typing import Any

from homeassistant.components.fan import DOMAIN, SUPPORT_SET_SPEED, FanEntity
from homeassistant.components.fan import DOMAIN, FanEntity, FanEntityFeature
from homeassistant.const import CONF_DEVICES, CONF_HOST, CONF_ID, CONF_MAC, CONF_NAME
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand All @@ -20,6 +22,10 @@
CasetaEntity,
)

FAN_SUPPORT = (
FanEntityFeature.SET_SPEED | FanEntityFeature.TURN_OFF | FanEntityFeature.TURN_ON
)

_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -93,14 +99,14 @@ def is_on(self):
return self._percentage and self._percentage > 0

@property
def percentage(self) -> int:
def percentage(self) -> int | None:
"""Return the current speed."""
return self._percentage

@property
def supported_features(self) -> int:
def supported_features(self) -> FanEntityFeature:
"""Flag supported features."""
return SUPPORT_SET_SPEED
return FAN_SUPPORT

@property
def speed_count(self) -> int:
Expand All @@ -109,10 +115,9 @@ def speed_count(self) -> int:

async def async_turn_on(
self,
speed: str = None,
percentage: int = None,
preset_mode: str = None,
**kwargs
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs: Any,
) -> None:
"""Instruct the fan to turn on."""
if percentage is None:
Expand All @@ -135,7 +140,7 @@ async def async_set_percentage(self, percentage: int) -> None:
self._percentage = percentage
self.async_write_ha_state()

async def async_turn_off(self, **kwargs) -> None:
async def async_turn_off(self, **kwargs: Any) -> None:
"""Instruct the fan to turn off."""
await self.async_set_percentage(0)

Expand Down
Loading
Loading