-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update manifest.json version * Add floor heating valves
- Loading branch information
Showing
10 changed files
with
324 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
"""Platform for binary sensor integration.""" | ||
from __future__ import annotations | ||
|
||
import logging | ||
from datetime import timedelta | ||
|
||
from homeassistant.components.binary_sensor import BinarySensorEntity, BinarySensorEntityDescription, \ | ||
BinarySensorDeviceClass | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity import DeviceInfo | ||
from homeassistant.helpers.typing import UndefinedType | ||
from homeassistant.helpers.update_coordinator import ( | ||
CoordinatorEntity, | ||
DataUpdateCoordinator, | ||
) | ||
|
||
from .const import DOMAIN, MANUFACTURER | ||
from .gateway_api import GatewayAPI | ||
from .structs.Valve import Valve | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry(hass, entry, async_add_entities): | ||
"""Set up the sensor platform.""" | ||
|
||
_LOGGER.debug("Setting up binary sensors") | ||
|
||
gateway_api = hass.data[DOMAIN][entry.entry_id]['gateway_api'] | ||
|
||
coordinator = AlphaCoordinator(hass, gateway_api) | ||
|
||
await coordinator.async_config_entry_first_refresh() | ||
|
||
entities = [] | ||
|
||
for valve in coordinator.data: | ||
entities.append(AlphaHomeBinarySensor( | ||
coordinator=coordinator, | ||
name=valve.name, | ||
description=BinarySensorEntityDescription(""), | ||
valve=valve | ||
)) | ||
|
||
async_add_entities(entities) | ||
|
||
|
||
class AlphaCoordinator(DataUpdateCoordinator): | ||
"""My custom coordinator.""" | ||
|
||
def __init__(self, hass: HomeAssistant, gateway_api: GatewayAPI): | ||
"""Initialize my coordinator.""" | ||
super().__init__( | ||
hass, | ||
_LOGGER, | ||
name="Alpha Innotec Binary Coordinator", | ||
update_interval=timedelta(seconds=30), | ||
) | ||
|
||
self.gateway_api: GatewayAPI = gateway_api | ||
|
||
async def _async_update_data(self) -> list[Valve]: | ||
"""Fetch data from API endpoint. | ||
This is the place to pre-process the data to lookup tables | ||
so entities can quickly look up their data. | ||
""" | ||
|
||
db_modules: dict = await self.hass.async_add_executor_job(self.gateway_api.db_modules) | ||
|
||
valves: list[Valve] = [] | ||
|
||
for module_id in db_modules["modules"]: | ||
module = db_modules["modules"][module_id] | ||
|
||
if module["productId"] != 3: | ||
continue | ||
|
||
for instance in module["instances"]: | ||
valve = Valve( | ||
identifier=module["deviceid"] + '-' + instance['instance'], | ||
name=module["name"] + '-' + instance['instance'], | ||
instance=instance["instance"], | ||
device_id=module["deviceid"], | ||
device_name=module["name"], | ||
status=instance["status"] | ||
) | ||
|
||
valves.append(valve) | ||
|
||
_LOGGER.debug("Finished getting valves from API") | ||
|
||
return valves | ||
|
||
|
||
class AlphaHomeBinarySensor(CoordinatorEntity, BinarySensorEntity): | ||
"""Representation of a Sensor.""" | ||
|
||
def __init__(self, coordinator: AlphaCoordinator, name: str, description: BinarySensorEntityDescription, valve: Valve) -> None: | ||
"""Pass coordinator to CoordinatorEntity.""" | ||
super().__init__(coordinator, context=valve.identifier) | ||
self.entity_description = description | ||
self._attr_name = name | ||
self.valve = valve | ||
|
||
@property | ||
def device_info(self) -> DeviceInfo: | ||
"""Return the device info.""" | ||
return DeviceInfo( | ||
identifiers={ | ||
(DOMAIN, self.valve.device_id) | ||
}, | ||
name=self.valve.device_name, | ||
manufacturer=MANUFACTURER, | ||
) | ||
|
||
@property | ||
def name(self) -> str | UndefinedType | None: | ||
return self._attr_name | ||
|
||
@property | ||
def unique_id(self) -> str: | ||
"""Return unique ID for this device.""" | ||
return self.valve.identifier | ||
|
||
@property | ||
def is_on(self) -> bool | None: | ||
return self.valve.status | ||
|
||
@property | ||
def device_class(self) -> BinarySensorDeviceClass | None: | ||
return BinarySensorDeviceClass.OPENING |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
PLATFORMS = [ | ||
Platform.SENSOR, | ||
Platform.BINARY_SENSOR, | ||
Platform.CLIMATE, | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Valve: | ||
def __init__(self, identifier: str, name: str, instance: str, device_id: str, device_name: str, status: bool): | ||
self.identifier = identifier | ||
self.name = name | ||
self.instance = instance | ||
self.device_id = device_id | ||
self.device_name = device_name | ||
self.status = status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
{ | ||
"success": true, | ||
"message": "", | ||
"loginRejected": false, | ||
"groups": [ | ||
{ | ||
"groupid": 1, | ||
"name": "rooms", | ||
"rooms": [ | ||
{ | ||
"id": 1, | ||
"appid": "01010002", | ||
"actualTemperature": 21, | ||
"isComfortMode": false, | ||
"desiredTemperature": 22, | ||
"roomstatus": 51, | ||
"desiredTempDay": 20, | ||
"desiredTempDay2": 18, | ||
"desiredTempNight": 18, | ||
"scheduleTempMin": 15, | ||
"scheduleTempMax": 28, | ||
"minTemperature": 18, | ||
"maxTemperature": 28, | ||
"cooling": false, | ||
"coolingEnabled": true, | ||
"imagepath": "/assets/images/room/default.png", | ||
"name": "Room 1", | ||
"orderindex": 1, | ||
"originalName": "Room 1", | ||
"status": "ok", | ||
"groupid": 1, | ||
"windowPosition": 0 | ||
}, | ||
{ | ||
"id": 2, | ||
"appid": "01020002", | ||
"actualTemperature": 20.5, | ||
"isComfortMode": false, | ||
"desiredTemperature": 20, | ||
"roomstatus": 41, | ||
"desiredTempDay": 20, | ||
"desiredTempDay2": 18, | ||
"desiredTempNight": 18, | ||
"scheduleTempMin": 15, | ||
"scheduleTempMax": 28, | ||
"minTemperature": 18, | ||
"maxTemperature": 28, | ||
"cooling": false, | ||
"coolingEnabled": true, | ||
"imagepath": "/assets/images/room/default.png", | ||
"name": "Room 2", | ||
"orderindex": 2, | ||
"originalName": "Room 3", | ||
"status": "ok", | ||
"groupid": 1, | ||
"windowPosition": 0 | ||
}, | ||
{ | ||
"id": 3, | ||
"appid": "01030002", | ||
"actualTemperature": 22, | ||
"isComfortMode": false, | ||
"desiredTemperature": 22.5, | ||
"roomstatus": 51, | ||
"desiredTempDay": 20, | ||
"desiredTempDay2": 18, | ||
"desiredTempNight": 18, | ||
"scheduleTempMin": 15, | ||
"scheduleTempMax": 28, | ||
"minTemperature": 18, | ||
"maxTemperature": 28, | ||
"cooling": false, | ||
"coolingEnabled": true, | ||
"imagepath": "/assets/images/room/default.png", | ||
"name": "Room 3", | ||
"orderindex": 3, | ||
"originalName": "Room 3", | ||
"status": "ok", | ||
"groupid": 1, | ||
"windowPosition": 0 | ||
}, | ||
{ | ||
"id": 4, | ||
"appid": "01040002", | ||
"isComfortMode": false, | ||
"desiredTemperature": 20, | ||
"roomstatus": 99, | ||
"desiredTempDay": 20, | ||
"desiredTempDay2": 18, | ||
"desiredTempNight": 18, | ||
"scheduleTempMin": 15, | ||
"scheduleTempMax": 28, | ||
"minTemperature": 18, | ||
"maxTemperature": 28, | ||
"cooling": false, | ||
"coolingEnabled": true, | ||
"imagepath": "/assets/images/room/default.png", | ||
"name": "Room 4", | ||
"orderindex": 4, | ||
"originalName": "Room 4", | ||
"status": "problem", | ||
"groupid": 1, | ||
"windowPosition": 0 | ||
}, | ||
{ | ||
"id": 5, | ||
"appid": "01050002", | ||
"actualTemperature": 22, | ||
"isComfortMode": false, | ||
"desiredTemperature": 22.5, | ||
"roomstatus": 51, | ||
"desiredTempDay": 20, | ||
"desiredTempDay2": 18, | ||
"desiredTempNight": 18, | ||
"scheduleTempMin": 15, | ||
"scheduleTempMax": 28, | ||
"minTemperature": 18, | ||
"maxTemperature": 28, | ||
"cooling": false, | ||
"coolingEnabled": true, | ||
"imagepath": "/assets/images/room/default.png", | ||
"name": "Room 5", | ||
"orderindex": 5, | ||
"originalName": "Room 5", | ||
"status": "ok", | ||
"groupid": 1, | ||
"windowPosition": 0 | ||
}, | ||
{ | ||
"id": 6, | ||
"appid": "01060002", | ||
"actualTemperature": 21.5, | ||
"isComfortMode": false, | ||
"desiredTemperature": 20, | ||
"roomstatus": 41, | ||
"desiredTempDay": 20, | ||
"desiredTempDay2": 18, | ||
"desiredTempNight": 18, | ||
"scheduleTempMin": 15, | ||
"scheduleTempMax": 28, | ||
"minTemperature": 18, | ||
"maxTemperature": 28, | ||
"cooling": false, | ||
"coolingEnabled": true, | ||
"imagepath": "/assets/images/room/default.png", | ||
"name": "Room 6", | ||
"orderindex": 6, | ||
"originalName": "Room 6", | ||
"status": "ok", | ||
"groupid": 1, | ||
"windowPosition": 0 | ||
} | ||
], | ||
"orderindex": 1 | ||
} | ||
], | ||
"language": "en", | ||
"performance": 0.907 | ||
} |
b715514
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HA Alpha Innotec
b715514
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HA Alpha Innotec
b715514
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HA Alpha Innotec
b715514
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HA Alpha Innotec
b715514
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HA Alpha Innotec
b715514
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HA Alpha Innotec