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

Commit

Permalink
specify min required version in hacs.json
Browse files Browse the repository at this point in the history
use release workflow to set it in const.py
  • Loading branch information
edenhaus committed Aug 27, 2021
1 parent de4a71f commit 1e8dd15
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 61 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: 13 additions & 3 deletions custom_components/deebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,37 @@
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 .haVersion import is_supported
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_supported():
if not is_ha_supported():
return False

# Store an instance of the "connecting" class that does the work of speaking
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
25 changes: 0 additions & 25 deletions custom_components/deebot/haVersion.py

This file was deleted.

3 changes: 1 addition & 2 deletions custom_components/deebot/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +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.1.0",
"awesomeversion>=21.8.1"
"deebotozmo==2.1.0"
],
"codeowners": ["@And3rsL", "@edenhaus"],
"iot_class": "cloud_polling"
Expand Down
41 changes: 12 additions & 29 deletions custom_components/deebot/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,13 @@
from deebotozmo.vacuum_bot import VacuumBot
from homeassistant.components.sensor import SensorEntity
from homeassistant.const import STATE_UNKNOWN, CONF_DESCRIPTION
from homeassistant.helpers.typing import StateType

from .haVersion import is_2021_9_or_later
from .const import DOMAIN, LAST_ERROR
from .helpers import get_device_info
from .hub import DeebotHub

_LOGGER = logging.getLogger(__name__)

_USES_NATIVE: bool = is_2021_9_or_later()


def _set_state(sensor: SensorEntity, state: Optional[StateType]):
if _USES_NATIVE:
sensor._attr_native_value = state
else:
sensor._attr_state = state


def _set_unit_of_measurement(sensor: SensorEntity, unit: str):
if _USES_NATIVE:
sensor._attr_native_unit_of_measurement = unit
else:
sensor._attr_unit_of_measurement = unit


async def async_setup_entry(hass, config_entry, async_add_devices):
"""Add sensors for passed config_entry in HA."""
Expand Down Expand Up @@ -90,7 +72,7 @@ async def async_added_to_hass(self) -> None:

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

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

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

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

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

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

_attr_native_unit_of_measurement = "%"

def __init__(self, vacuum_bot: VacuumBot, device_id: str):
"""Initialize the Sensor."""
super(DeebotComponentSensor, self).__init__(vacuum_bot, device_id)
self._attr_icon = "mdi:air-filter" if device_id == COMPONENT_FILTER else "mdi:broom"
self._id = device_id
_set_unit_of_measurement(self, "%")

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_event(event: LifeSpanEvent):
if self._id == event.type:
_set_state(self, event.percent)
self._attr_native_value = event.percent
self.async_write_ha_state()

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

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

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

self.async_write_ha_state()

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

async def on_event(event: ErrorEvent):
_set_state(self, 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 1e8dd15

Please sign in to comment.