Skip to content

Commit

Permalink
Merge pull request #29 from Jezza34000/develop
Browse files Browse the repository at this point in the history
♿ add fastpolling for switch action
  • Loading branch information
Jezza34000 authored Feb 11, 2025
2 parents a03b18a + 9428959 commit 328dff6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ repos:
- id: black

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.4
rev: v0.9.5
hooks:
- id: ruff
args:
Expand Down
5 changes: 5 additions & 0 deletions custom_components/petkit/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class PetKitButtonDesc(PetKitDescSensorBase, ButtonEntityDescription):
{DeviceAction.START: LBCommand.CLEANING},
),
only_for_types=DEVICES_LITTER_BOX,
is_available=lambda device: device.state.work_state is None,
),
PetKitButtonDesc(
key="Maintenance mode",
Expand All @@ -109,6 +110,7 @@ class PetKitButtonDesc(PetKitDescSensorBase, ButtonEntityDescription):
{DeviceAction.START: LBCommand.MAINTENANCE},
),
only_for_types=[T4],
is_available=lambda device: device.state.work_state is None,
),
PetKitButtonDesc(
key="Exit maintenance mode",
Expand All @@ -119,6 +121,8 @@ class PetKitButtonDesc(PetKitDescSensorBase, ButtonEntityDescription):
{DeviceAction.END: LBCommand.MAINTENANCE},
),
only_for_types=[T4],
is_available=lambda device: device.state.work_state is not None
and device.state.work_state.work_mode == 9,
),
PetKitButtonDesc(
key="Dump litter",
Expand All @@ -129,6 +133,7 @@ class PetKitButtonDesc(PetKitDescSensorBase, ButtonEntityDescription):
{DeviceAction.START: LBCommand.DUMPING},
),
only_for_types=DEVICES_LITTER_BOX,
is_available=lambda device: device.state.work_state is None,
),
PetKitButtonDesc(
key="Pause",
Expand Down
5 changes: 4 additions & 1 deletion custom_components/petkit/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import asyncio
from collections.abc import Callable
from dataclasses import dataclass
from datetime import timedelta
from typing import TYPE_CHECKING, Any

from pypetkitapi import (
Expand All @@ -22,7 +23,7 @@
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
from homeassistant.const import EntityCategory

from .const import LOGGER, POWER_ONLINE_STATE
from .const import LOGGER, MIN_SCAN_INTERVAL, POWER_ONLINE_STATE
from .entity import PetKitDescSensorBase, PetkitEntity

if TYPE_CHECKING:
Expand Down Expand Up @@ -722,5 +723,7 @@ async def async_turn_off(self, **_: Any) -> None:

async def _update_coordinator_data(self, result: bool) -> None:
"""Update the coordinator data based on the result."""
self.coordinator.update_interval = timedelta(seconds=MIN_SCAN_INTERVAL)
self.coordinator.fast_poll_tic = 3
await asyncio.sleep(1)
await self.coordinator.async_request_refresh()

0 comments on commit 328dff6

Please sign in to comment.