Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
support HA 2022.7 (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus committed Jun 29, 2022
1 parent 1d9d6d0 commit 354b072
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion custom_components/deebot/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
################################
# Do not change! Will be set by release workflow
INTEGRATION_VERSION = "main" # git tag will be used
MIN_REQUIRED_HA_VERSION = "2022.5.0b0" # set min required version in hacs.json
MIN_REQUIRED_HA_VERSION = "2022.7.0b0" # set min required version in hacs.json
################################

# Values below can be changed
Expand Down
30 changes: 14 additions & 16 deletions custom_components/deebot/number.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Number module."""
import logging
from typing import Optional

from deebot_client.commands import SetVolume
Expand All @@ -16,8 +15,6 @@
from .entity import DeebotEntity
from .hub import DeebotHub

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(
hass: HomeAssistant,
Expand All @@ -44,19 +41,19 @@ class VolumeEntity(DeebotEntity, NumberEntity): # type: ignore
entity_category=EntityCategory.CONFIG,
)

_attr_min_value = 0
_attr_max_value = 10
_attr_step = 1.0
_attr_value = None
_attr_native_min_value = 0
_attr_native_max_value = 10
_attr_native_step = 1.0
_attr_native_value: float | None = None

async def async_added_to_hass(self) -> None:
"""Set up the event listeners now that hass is ready."""
await super().async_added_to_hass()

async def on_volume(event: VolumeEvent) -> None:
if event.maximum is not None:
self._attr_max_value = event.maximum
self._attr_value = event.volume
self._attr_native_max_value = event.maximum
self._attr_native_value = event.volume
self.async_write_ha_state()

listener: EventListener = self._vacuum_bot.events.subscribe(
Expand All @@ -67,21 +64,22 @@ async def on_volume(event: VolumeEvent) -> None:
@property
def icon(self) -> Optional[str]:
"""Return the icon to use in the frontend, if any."""
if self._attr_value is not None:
if self._attr_native_value is not None:
arrays = array_split(
range(self._attr_min_value + 1, self._attr_max_value + 1), 3
range(self._attr_native_min_value + 1, self._attr_native_max_value + 1),
3,
)
if self._attr_value == self._attr_min_value:
if self._attr_native_value == self._attr_native_min_value:
return "mdi:volume-off"
if self._attr_value in arrays[0]:
if self._attr_native_value in arrays[0]:
return "mdi:volume-low"
if self._attr_value in arrays[1]:
if self._attr_native_value in arrays[1]:
return "mdi:volume-medium"
if self._attr_value in arrays[2]:
if self._attr_native_value in arrays[2]:
return "mdi:volume-high"

return "mdi:volume-medium"

async def async_set_value(self, value: float) -> None:
async def async_set_native_value(self, value: float) -> None:
"""Set new value."""
await self._vacuum_bot.execute_command(SetVolume(int(value)))
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"filename": "deebot.zip",
"homeassistant": "2022.5.0b0",
"homeassistant": "2022.7.0b0",
"name": "Deebot 4 Home Assistant",
"render_readme": true,
"zip_release": true
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# git+https://github.com/DeebotUniverse/client.py@main#deebot-client==0.0.1b1
deebot-client==1.4.1

homeassistant>=2022.5.0.b0
homeassistant>=2022.7.0.b0
mypy==0.961

numpy>=1.21.2
Expand Down

0 comments on commit 354b072

Please sign in to comment.