Bump melnor-bluetooth to v0.0.20 (#78642)
parent
08e6e27a3b
commit
b87c452106
|
@ -12,5 +12,5 @@
|
||||||
"documentation": "https://www.home-assistant.io/integrations/melnor",
|
"documentation": "https://www.home-assistant.io/integrations/melnor",
|
||||||
"iot_class": "local_polling",
|
"iot_class": "local_polling",
|
||||||
"name": "Melnor Bluetooth",
|
"name": "Melnor Bluetooth",
|
||||||
"requirements": ["melnor-bluetooth==0.0.15"]
|
"requirements": ["melnor-bluetooth==0.0.20"]
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,16 +38,7 @@ class MelnorSensorEntityDescription(
|
||||||
"""Describes Melnor sensor entity."""
|
"""Describes Melnor sensor entity."""
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
sensors = [
|
||||||
hass: HomeAssistant,
|
|
||||||
config_entry: ConfigEntry,
|
|
||||||
async_add_devices: AddEntitiesCallback,
|
|
||||||
) -> None:
|
|
||||||
"""Set up the sensor platform."""
|
|
||||||
|
|
||||||
coordinator: MelnorDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
|
||||||
|
|
||||||
sensors: list[MelnorSensorEntityDescription] = [
|
|
||||||
MelnorSensorEntityDescription(
|
MelnorSensorEntityDescription(
|
||||||
device_class=SensorDeviceClass.BATTERY,
|
device_class=SensorDeviceClass.BATTERY,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
@ -69,7 +60,17 @@ async def async_setup_entry(
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
async_add_devices(
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
|
"""Set up the sensor platform."""
|
||||||
|
|
||||||
|
coordinator: MelnorDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
|
|
||||||
|
async_add_entities(
|
||||||
MelnorSensorEntity(
|
MelnorSensorEntity(
|
||||||
coordinator,
|
coordinator,
|
||||||
description,
|
description,
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable, Coroutine
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
@ -21,16 +21,11 @@ from .const import DOMAIN
|
||||||
from .models import MelnorDataUpdateCoordinator, MelnorZoneEntity
|
from .models import MelnorDataUpdateCoordinator, MelnorZoneEntity
|
||||||
|
|
||||||
|
|
||||||
def set_is_watering(valve: Valve, value: bool) -> None:
|
|
||||||
"""Set the is_watering state of a valve."""
|
|
||||||
valve.is_watering = value
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class MelnorSwitchEntityDescriptionMixin:
|
class MelnorSwitchEntityDescriptionMixin:
|
||||||
"""Mixin for required keys."""
|
"""Mixin for required keys."""
|
||||||
|
|
||||||
on_off_fn: Callable[[Valve, bool], Any]
|
on_off_fn: Callable[[Valve, bool], Coroutine[Any, Any, None]]
|
||||||
state_fn: Callable[[Valve], Any]
|
state_fn: Callable[[Valve], Any]
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,6 +36,18 @@ class MelnorSwitchEntityDescription(
|
||||||
"""Describes Melnor switch entity."""
|
"""Describes Melnor switch entity."""
|
||||||
|
|
||||||
|
|
||||||
|
switches = [
|
||||||
|
MelnorSwitchEntityDescription(
|
||||||
|
device_class=SwitchDeviceClass.SWITCH,
|
||||||
|
icon="mdi:sprinkler",
|
||||||
|
key="manual",
|
||||||
|
name="Manual",
|
||||||
|
on_off_fn=lambda valve, bool: valve.set_is_watering(bool),
|
||||||
|
state_fn=lambda valve: valve.is_watering,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
|
@ -56,20 +63,8 @@ async def async_setup_entry(
|
||||||
valve = coordinator.data[f"zone{i}"]
|
valve = coordinator.data[f"zone{i}"]
|
||||||
if valve is not None:
|
if valve is not None:
|
||||||
|
|
||||||
entities.append(
|
for description in switches:
|
||||||
MelnorZoneSwitch(
|
entities.append(MelnorZoneSwitch(coordinator, valve, description))
|
||||||
coordinator,
|
|
||||||
valve,
|
|
||||||
MelnorSwitchEntityDescription(
|
|
||||||
device_class=SwitchDeviceClass.SWITCH,
|
|
||||||
icon="mdi:sprinkler",
|
|
||||||
key="manual",
|
|
||||||
name="Manual",
|
|
||||||
on_off_fn=set_is_watering,
|
|
||||||
state_fn=lambda valve: valve.is_watering,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
async_add_devices(entities)
|
async_add_devices(entities)
|
||||||
|
|
||||||
|
@ -98,12 +93,10 @@ class MelnorZoneSwitch(MelnorZoneEntity, SwitchEntity):
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn the device on."""
|
"""Turn the device on."""
|
||||||
self.entity_description.on_off_fn(self._valve, True)
|
await self.entity_description.on_off_fn(self._valve, True)
|
||||||
await self._device.push_state()
|
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn the device off."""
|
"""Turn the device off."""
|
||||||
self.entity_description.on_off_fn(self._valve, False)
|
await self.entity_description.on_off_fn(self._valve, False)
|
||||||
await self._device.push_state()
|
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
|
@ -1046,7 +1046,7 @@ mcstatus==6.0.0
|
||||||
meater-python==0.0.8
|
meater-python==0.0.8
|
||||||
|
|
||||||
# homeassistant.components.melnor
|
# homeassistant.components.melnor
|
||||||
melnor-bluetooth==0.0.15
|
melnor-bluetooth==0.0.20
|
||||||
|
|
||||||
# homeassistant.components.message_bird
|
# homeassistant.components.message_bird
|
||||||
messagebird==1.2.0
|
messagebird==1.2.0
|
||||||
|
|
|
@ -748,7 +748,7 @@ mcstatus==6.0.0
|
||||||
meater-python==0.0.8
|
meater-python==0.0.8
|
||||||
|
|
||||||
# homeassistant.components.melnor
|
# homeassistant.components.melnor
|
||||||
melnor-bluetooth==0.0.15
|
melnor-bluetooth==0.0.20
|
||||||
|
|
||||||
# homeassistant.components.meteo_france
|
# homeassistant.components.meteo_france
|
||||||
meteofrance-api==1.0.2
|
meteofrance-api==1.0.2
|
||||||
|
|
|
@ -6,7 +6,7 @@ from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
from bleak.backends.device import BLEDevice
|
from bleak.backends.device import BLEDevice
|
||||||
from bleak.backends.scanner import AdvertisementData
|
from bleak.backends.scanner import AdvertisementData
|
||||||
from melnor_bluetooth.device import Device, Valve
|
from melnor_bluetooth.device import Device
|
||||||
|
|
||||||
from homeassistant.components.bluetooth.models import BluetoothServiceInfoBleak
|
from homeassistant.components.bluetooth.models import BluetoothServiceInfoBleak
|
||||||
from homeassistant.components.melnor.const import DOMAIN
|
from homeassistant.components.melnor.const import DOMAIN
|
||||||
|
@ -52,6 +52,34 @@ FAKE_SERVICE_INFO_2 = BluetoothServiceInfoBleak(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class MockedValve:
|
||||||
|
"""Mocked class for a Valve."""
|
||||||
|
|
||||||
|
_id: int
|
||||||
|
_is_watering: bool
|
||||||
|
_manual_watering_minutes: int
|
||||||
|
|
||||||
|
def __init__(self, identifier: int) -> None:
|
||||||
|
"""Initialize a mocked valve."""
|
||||||
|
self._id = identifier
|
||||||
|
self._is_watering = False
|
||||||
|
self._manual_watering_minutes = 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def id(self) -> int:
|
||||||
|
"""Return the valve id."""
|
||||||
|
return self._id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_watering(self):
|
||||||
|
"""Return true if the valve is currently watering."""
|
||||||
|
return self._is_watering
|
||||||
|
|
||||||
|
async def set_is_watering(self, is_watering: bool):
|
||||||
|
"""Set the valve to manual watering."""
|
||||||
|
self._is_watering = is_watering
|
||||||
|
|
||||||
|
|
||||||
def mock_config_entry(hass: HomeAssistant):
|
def mock_config_entry(hass: HomeAssistant):
|
||||||
"""Return a mock config entry."""
|
"""Return a mock config entry."""
|
||||||
|
|
||||||
|
@ -83,10 +111,10 @@ def mock_melnor_device():
|
||||||
device.name = "test_melnor"
|
device.name = "test_melnor"
|
||||||
device.rssi = -50
|
device.rssi = -50
|
||||||
|
|
||||||
device.zone1 = Valve(0, device)
|
device.zone1 = MockedValve(0)
|
||||||
device.zone2 = Valve(1, device)
|
device.zone2 = MockedValve(1)
|
||||||
device.zone3 = Valve(2, device)
|
device.zone3 = MockedValve(2)
|
||||||
device.zone4 = Valve(3, device)
|
device.zone4 = MockedValve(3)
|
||||||
|
|
||||||
device.__getitem__.side_effect = lambda key: getattr(device, key)
|
device.__getitem__.side_effect = lambda key: getattr(device, key)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue