Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #185 from And3rsL/2021.9
Browse files Browse the repository at this point in the history
Add min required HA version check + 2021.9 compatibility
  • Loading branch information
edenhaus authored Aug 30, 2021
2 parents 69c2b65 + 1e8dd15 commit b0923e6
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 20 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ jobs:
run: |
name=$(find custom_components/ -type d -maxdepth 1 | tail -n 1 | cut -d "/" -f2)
echo "::set-output name=name::$name"
min_ha_version=$(jq -r '.homeassistant' ${{ github.workspace }}/hacs.json)
echo "::set-output name=min_ha_version::$min_ha_version"
- name: 🖊️ Set version number
run: |
sed -i '/INTEGRATION_VERSION = /c\INTEGRATION_VERSION = "${{ steps.version.outputs.version }}"' \
"${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/const.py"
jq '.version = "${{ steps.version.outputs.version }}"' \
"${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/manifest.json" > tmp \
&& mv -f tmp "${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/manifest.json"
- name: 🖊️ Set min required HA version
run: |
sed -i '/MIN_REQUIRED_HA_VERSION = /c\MIN_REQUIRED_HA_VERSION = "${{ steps.information.outputs.min_ha_version }}"' \
"${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/const.py"
- name: 👀 Validate data
run: |
if ! grep -q 'INTEGRATION_VERSION = "${{ steps.version.outputs.version }}"' ${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/const.py; then
Expand All @@ -46,6 +52,11 @@ jobs:
echo "$manifestversion"
exit 1
fi
if ! grep -q 'MIN_REQUIRED_HA_VERSION = "${{ steps.information.outputs.min_ha_version }}"' ${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/const.py; then
echo "The MIN_REQUIRED_HA_VERSION in custom_components/${{ steps.information.outputs.name }}/const.py was not correct"
cat ${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/const.py | grep MIN_REQUIRED_HA_VERSION
exit 1
fi
- name: 📦 Create zip file for the integration
run: |
cd "${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}"
Expand Down
16 changes: 15 additions & 1 deletion custom_components/deebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,39 @@
import asyncio
import logging

from awesomeversion import AwesomeVersion
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_DEVICES, CONF_VERIFY_SSL, CONF_USERNAME
from homeassistant.const import __version__ as HA_VERSION
from homeassistant.core import HomeAssistant

from . import hub
from .const import DOMAIN, STARTUP_MESSAGE, CONF_BUMPER, CONF_CLIENT_DEVICE_ID
from .const import DOMAIN, STARTUP_MESSAGE, CONF_BUMPER, CONF_CLIENT_DEVICE_ID, MIN_REQUIRED_HA_VERSION
from .helpers import get_bumper_device_id

_LOGGER = logging.getLogger(__name__)

PLATFORMS = ["sensor", "binary_sensor", "vacuum", "camera"]


def is_ha_supported() -> bool:
if AwesomeVersion(HA_VERSION) >= MIN_REQUIRED_HA_VERSION:
return True

_LOGGER.error(f"Unsupported HA version! Please upgrade home assistant at least to \"{MIN_REQUIRED_HA_VERSION}\"")
return False


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up this integration using UI."""

if DOMAIN not in hass.data:
# Print startup message
_LOGGER.info(STARTUP_MESSAGE)

if not is_ha_supported():
return False

# Store an instance of the "connecting" class that does the work of speaking
# with your actual devices.
deebot_hub = hub.DeebotHub(hass, entry.data)
Expand Down
8 changes: 5 additions & 3 deletions custom_components/deebot/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ def __init__(self, vacuum_bot: VacuumBot, device_id: str):
def device_info(self) -> Optional[Dict[str, Any]]:
return get_device_info(self._vacuum_bot)

async def async_camera_image(self):
"""Return a still image response from the camera."""
return base64.decodebytes(self._vacuum_bot.map.get_base64_map())
async def async_camera_image(self, width: Optional[int] = None, height: Optional[int] = None) -> Optional[bytes]:
"""Return a still image response from the camera.
Integrations may choose to ignore the height parameter in order to preserve aspect ratio"""

return base64.decodebytes(self._vacuum_bot.map.get_base64_map(width))

async def async_added_to_hass(self) -> None:
"""Set up the event listeners now that hass is ready."""
Expand Down
8 changes: 7 additions & 1 deletion custom_components/deebot/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
)
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, CONF_VERIFY_SSL

################################
# Do not change! Will be set by release workflow
INTEGRATION_VERSION = "main" # git tag will be used
MIN_REQUIRED_HA_VERSION = "0.0.0" # set min required version in hacs.json
################################

# Values below can be changed
DOMAIN = "deebot"
INTEGRATION_VERSION = "main"
ISSUE_URL = "https://github.com/And3rsL/Deebot-for-Home-Assistant/issues"

STARTUP_MESSAGE = f"""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/deebot/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"documentation": "https://github.com/And3rsL/Deebot-for-Home-Assistant",
"issue_tracker": "https://github.com/And3rsL/Deebot-for-Home-Assistant/issues",
"requirements": [
"deebotozmo==2.0.3"
"deebotozmo==2.1.0"
],
"codeowners": ["@And3rsL", "@edenhaus"],
"iot_class": "cloud_polling"
Expand Down
26 changes: 13 additions & 13 deletions custom_components/deebot/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from deebotozmo.events import CleanLogEvent, WaterInfoEvent, LifeSpanEvent, StatsEvent, EventListener, ErrorEvent, \
StatusEvent
from deebotozmo.vacuum_bot import VacuumBot
from homeassistant.components.sensor import SensorEntity
from homeassistant.const import STATE_UNKNOWN, CONF_DESCRIPTION
from homeassistant.helpers.entity import Entity

from .const import DOMAIN, LAST_ERROR
from .helpers import get_device_info
Expand Down Expand Up @@ -43,7 +43,7 @@ async def async_setup_entry(hass, config_entry, async_add_devices):
async_add_devices(new_devices)


class DeebotBaseSensor(Entity):
class DeebotBaseSensor(SensorEntity):
"""Deebot base sensor"""

_attr_should_poll = False
Expand Down Expand Up @@ -72,7 +72,7 @@ async def async_added_to_hass(self) -> None:

async def on_event(event: StatusEvent):
if not event.available:
self._attr_state = STATE_UNKNOWN
self._attr_native_value = STATE_UNKNOWN
self.async_write_ha_state()

listener: EventListener = self._vacuum_bot.statusEvents.subscribe(on_event)
Expand All @@ -94,9 +94,9 @@ async def async_added_to_hass(self) -> None:

async def on_event(event: CleanLogEvent):
if event.logs:
self._attr_state = event.logs[0].imageUrl
self._attr_native_value = event.logs[0].imageUrl
else:
self._attr_state = STATE_UNKNOWN
self._attr_native_value = STATE_UNKNOWN
self.async_write_ha_state()

listener: EventListener = self._vacuum_bot.cleanLogsEvents.subscribe(on_event)
Expand All @@ -118,7 +118,7 @@ async def async_added_to_hass(self) -> None:

async def on_event(event: WaterInfoEvent):
if event.amount:
self._attr_state = event.amount
self._attr_native_value = event.amount
self.async_write_ha_state()

listener: EventListener = self._vacuum_bot.waterEvents.subscribe(on_event)
Expand All @@ -128,7 +128,7 @@ async def on_event(event: WaterInfoEvent):
class DeebotComponentSensor(DeebotBaseSensor):
"""Deebot Sensor"""

_attr_unit_of_measurement = "%"
_attr_native_unit_of_measurement = "%"

def __init__(self, vacuum_bot: VacuumBot, device_id: str):
"""Initialize the Sensor."""
Expand All @@ -142,7 +142,7 @@ async def async_added_to_hass(self) -> None:

async def on_event(event: LifeSpanEvent):
if self._id == event.type:
self._attr_state = event.percent
self._attr_native_value = event.percent
self.async_write_ha_state()

listener: EventListener = self._vacuum_bot.lifespanEvents.subscribe(on_event)
Expand All @@ -159,10 +159,10 @@ def __init__(self, vacuum_bot: VacuumBot, type: str):
self._type = type
if type == "area":
self._attr_icon = "mdi:floor-plan"
self._attr_unit_of_measurement = "mq"
self._attr_native_unit_of_measurement = "mq"
elif type == "time":
self._attr_icon = "mdi:timer-outline"
self._attr_unit_of_measurement = "min"
self._attr_native_unit_of_measurement = "min"
elif type == "type":
self._attr_icon = "mdi:cog"

Expand All @@ -178,9 +178,9 @@ async def on_event(event: StatsEvent):
return

if self._type == "time":
self._attr_state = round(value / 60)
self._attr_native_value = round(value / 60)
else:
self._attr_state = value
self._attr_native_value = value

self.async_write_ha_state()

Expand All @@ -202,7 +202,7 @@ async def async_added_to_hass(self) -> None:
await super().async_added_to_hass()

async def on_event(event: ErrorEvent):
self._attr_state = event.code
self._attr_native_value = event.code
self._attr_extra_state_attributes = {
CONF_DESCRIPTION: event.description
}
Expand Down
3 changes: 2 additions & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"zip_release": true,
"filename": "deebot.zip",
"hide_default_branch": true,
"domain": ["deebot", "vacuum", "sensor", "binary_sensor", "camera"]
"domain": ["deebot", "vacuum", "sensor", "binary_sensor", "camera"],
"homeassistant": "2021.9.0b0"
}

0 comments on commit b0923e6

Please sign in to comment.