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

Commit

Permalink
1.12.0 (#109)
Browse files Browse the repository at this point in the history
ventilation service fix + HA 2021.12
  • Loading branch information
thomasgermain committed Jan 3, 2022
1 parent 52e3e14 commit b30c318
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 45 deletions.
41 changes: 21 additions & 20 deletions custom_components/multimatic/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
from pymultimatic.model import Device, OperatingModes, QuickModes, Room, SettingModes

from homeassistant.components.binary_sensor import (
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_CONNECTIVITY,
DEVICE_CLASS_LOCK,
DEVICE_CLASS_PROBLEM,
DEVICE_CLASS_WINDOW,
DOMAIN,
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC
Expand Down Expand Up @@ -124,7 +120,9 @@ class RoomWindow(MultimaticEntity, BinarySensorEntity):

def __init__(self, coordinator: MultimaticCoordinator, room: Room) -> None:
"""Initialize entity."""
super().__init__(coordinator, DOMAIN, f"{room.name}_{DEVICE_CLASS_WINDOW}")
super().__init__(
coordinator, DOMAIN, f"{room.name}_{BinarySensorDeviceClass.WINDOW}"
)
self._room_id = room.id

@property
Expand All @@ -140,7 +138,7 @@ def available(self):
@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
return DEVICE_CLASS_WINDOW
return BinarySensorDeviceClass.WINDOW

@property
def name(self) -> str:
Expand Down Expand Up @@ -182,7 +180,7 @@ def device_info(self):
}

@property
def device_state_attributes(self):
def extra_state_attributes(self):
"""Return the state attributes."""
device = self.device
return {
Expand Down Expand Up @@ -222,7 +220,7 @@ def __init__(
self, coordinator: MultimaticCoordinator, device: Device, room: Room
) -> None:
"""Initialize entity."""
super().__init__(coordinator, device, DEVICE_CLASS_LOCK)
super().__init__(coordinator, device, BinarySensorDeviceClass.LOCK)
self._room_id = room.id

@property
Expand All @@ -243,7 +241,7 @@ def room(self) -> Room:
@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
return DEVICE_CLASS_LOCK
return BinarySensorDeviceClass.LOCK

@property
def entity_category(self) -> str | None:
Expand All @@ -256,7 +254,7 @@ class RoomDeviceBattery(RoomDeviceEntity):

def __init__(self, coordinator: MultimaticCoordinator, device: Device) -> None:
"""Initialize entity."""
super().__init__(coordinator, device, DEVICE_CLASS_BATTERY)
super().__init__(coordinator, device, BinarySensorDeviceClass.BATTERY)

@property
def is_on(self):
Expand All @@ -266,7 +264,7 @@ def is_on(self):
@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
return DEVICE_CLASS_BATTERY
return BinarySensorDeviceClass.BATTERY

@property
def entity_category(self) -> str | None:
Expand All @@ -279,7 +277,7 @@ class RoomDeviceConnectivity(RoomDeviceEntity):

def __init__(self, coordinator: MultimaticCoordinator, device: Device) -> None:
"""Initialize entity."""
super().__init__(coordinator, device, DEVICE_CLASS_CONNECTIVITY)
super().__init__(coordinator, device, BinarySensorDeviceClass.CONNECTIVITY)

@property
def is_on(self):
Expand All @@ -289,7 +287,7 @@ def is_on(self):
@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
return DEVICE_CLASS_CONNECTIVITY
return BinarySensorDeviceClass.CONNECTIVITY

@property
def entity_category(self) -> str | None:
Expand Down Expand Up @@ -385,7 +383,7 @@ def name(self):
@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
return DEVICE_CLASS_CONNECTIVITY
return BinarySensorDeviceClass.CONNECTIVITY

@property
def entity_category(self) -> str | None:
Expand Down Expand Up @@ -433,7 +431,7 @@ def device_info(self):
}

@property
def device_state_attributes(self):
def extra_state_attributes(self):
"""Return the state attributes."""
if self.available:
return {"device_id": self._boiler_id, "error": self.boiler_status.is_error}
Expand All @@ -457,7 +455,7 @@ def boiler_status(self):
@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
return DEVICE_CLASS_PROBLEM
return BinarySensorDeviceClass.PROBLEM

@property
def entity_category(self) -> str | None:
Expand All @@ -479,7 +477,10 @@ def __init__(self, coordinator: MultimaticCoordinator) -> None:
@property
def is_on(self):
"""Return true if the binary sensor is on."""
return self.coordinator.data.errors and len(self.coordinator.data.errors) > 0
if self.coordinator.data.errors:
return len(self.coordinator.data.errors) > 0
else:
return False

@property
def state_attributes(self):
Expand All @@ -503,7 +504,7 @@ def state_attributes(self):
@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
return DEVICE_CLASS_PROBLEM
return BinarySensorDeviceClass.PROBLEM

@property
def name(self):
Expand Down Expand Up @@ -564,7 +565,7 @@ def __init__(self, coordinator: MultimaticCoordinator) -> None:
@property
def is_on(self):
"""Return true if the binary sensor is on."""
return self.coordinator.data
return False if self.coordinator.data is None else True

@property
def state_attributes(self):
Expand Down
9 changes: 5 additions & 4 deletions custom_components/multimatic/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,13 @@ async def set_fan_operating_mode(self, entity, mode: Mode):
entity.component.operating_mode = mode
await self._refresh(touch_system, entity)

async def set_fan_day_level(self, level):
async def set_fan_day_level(self, entity, level):
"""Set fan day level."""
await self._manager.set_ventilation_day_level(level)
await self._manager.set_ventilation_day_level(entity.component.id, level)

async def set_fan_night_level(self, level):
async def set_fan_night_level(self, entity, level):
"""Set fan night level."""
await self._manager.set_ventilation_night_level(level)
await self._manager.set_ventilation_night_level(entity.component.id, level)

async def _remove_quick_mode_no_refresh(self, entity=None):
removed = False
Expand Down Expand Up @@ -530,6 +530,7 @@ async def _first_fetch_data(self):
self.name,
exc_info=True,
)
return None
else:
raise

Expand Down
10 changes: 9 additions & 1 deletion custom_components/multimatic/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from homeassistant.components.fan import DOMAIN, SUPPORT_PRESET_MODE, FanEntity
from homeassistant.helpers import entity_platform

from .const import VENTILATION
from .const import ATTR_LEVEL, VENTILATION
from .coordinator import MultimaticCoordinator
from .entities import MultimaticEntity
from .service import (
Expand Down Expand Up @@ -136,3 +136,11 @@ def available(self):
def active_mode(self):
"""Return the active mode."""
return self.coordinator.api.get_active_mode(self.component)

async def set_ventilation_day_level(self, **kwargs):
"""Service method to set day level."""
await self.coordinator.api.set_fan_day_level(self, kwargs.get(ATTR_LEVEL))

async def set_ventilation_night_level(self, **kwargs):
"""Service method to set night level."""
await self.coordinator.api.set_fan_night_level(self, kwargs.get(ATTR_LEVEL))
4 changes: 2 additions & 2 deletions custom_components/multimatic/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"documentation": "https://github.com/thomasgermain/vaillant-component",
"issue_tracker": "https://github.com/thomasgermain/vaillant-component/issues",
"requirements": [
"pymultimatic==0.6.5"
"pymultimatic==0.6.6"
],
"ssdp": [],
"zeroconf": [],
Expand All @@ -14,6 +14,6 @@
"codeowners": [
"@thomasgermain"
],
"version": "1.11.0",
"version": "1.12.0",
"iot_class": "cloud_polling"
}
12 changes: 5 additions & 7 deletions custom_components/multimatic/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
from pymultimatic.model import EmfReport, Report

from homeassistant.components.sensor import (
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE,
DOMAIN,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
SensorDeviceClass,
SensorEntity,
)
from homeassistant.const import (
Expand All @@ -32,9 +30,9 @@
_LOGGER = logging.getLogger(__name__)

UNIT_TO_DEVICE_CLASS = {
"bar": DEVICE_CLASS_PRESSURE,
"bar": SensorDeviceClass.PRESSURE,
"ppm": "",
"°C": DEVICE_CLASS_TEMPERATURE,
"°C": SensorDeviceClass.TEMPERATURE,
}


Expand Down Expand Up @@ -92,7 +90,7 @@ def name(self) -> str:
@property
def device_class(self) -> str:
"""Return the class of this device, from component DEVICE_CLASSES."""
return DEVICE_CLASS_TEMPERATURE
return SensorDeviceClass.TEMPERATURE

@property
def state_class(self) -> str | None:
Expand Down Expand Up @@ -226,7 +224,7 @@ def device_info(self):
@property
def device_class(self) -> str | None:
"""Return the class of this device, from component DEVICE_CLASSES."""
return DEVICE_CLASS_ENERGY
return SensorDeviceClass.ENERGY

@property
def name(self) -> str | None:
Expand Down
15 changes: 5 additions & 10 deletions custom_components/multimatic/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@

SERVICE_SET_VENTILATION_DAY_LEVEL_SCHEMA = vol.Schema(
{
vol.Required(ATTR_ENTITY_ID): vol.All(vol.Coerce(str)),
vol.Required(ATTR_LEVEL): vol.All(vol.Coerce(int), vol.Clamp(min=1, max=6)),
}
)
Expand Down Expand Up @@ -98,10 +99,12 @@
"schema": SERVICE_REQUEST_HVAC_UPDATE_SCHEMA,
},
SERVICE_SET_VENTILATION_NIGHT_LEVEL: {
"schema": SERVICE_SET_VENTILATION_NIGHT_LEVEL_SCHEMA
"schema": SERVICE_SET_VENTILATION_NIGHT_LEVEL_SCHEMA,
"entity": True,
},
SERVICE_SET_VENTILATION_DAY_LEVEL: {
"schema": SERVICE_SET_VENTILATION_DAY_LEVEL_SCHEMA
"schema": SERVICE_SET_VENTILATION_DAY_LEVEL_SCHEMA,
"entity": True,
},
}

Expand Down Expand Up @@ -148,11 +151,3 @@ async def set_quick_mode(self, data):
async def request_hvac_update(self, data):
"""Ask multimatic API to get data from the installation."""
await self.api.request_hvac_update()

async def set_ventilation_day_level(self, data):
"""Set ventilation day level."""
await self.api.set_fan_day_level(data.get(ATTR_LEVEL))

async def set_ventilation_night_level(self, data):
"""Set ventilation day level."""
await self.api.set_fan_night_level(data.get(ATTR_LEVEL))
20 changes: 20 additions & 0 deletions custom_components/multimatic/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,23 @@ remove_quick_veto:

request_hvac_update:
description: Ask multimatic API to get data from your installation.

set_ventilation_day_level:
description: Set day level ventilation
fields:
entity_id:
description: Entity id of the fan
example: fan.bathroom
level:
description: Level to set (required)
example: 1

set_ventilation_night_level:
description: Set night level ventilation
fields:
entity_id:
description: Entity id of the fan
example: fan.bathroom
level:
description: Level to set (required)
example: 2
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"name": "multimatic",
"domains": ["binary_sensor", "climate", "fan", "sensor", "water_heater"],
"render_readme": true,
"homeassistant": "2021.11.0"
"homeassistant": "2021.12.0"
}

0 comments on commit b30c318

Please sign in to comment.