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

Commit

Permalink
Sync with upstream dev branch
Browse files Browse the repository at this point in the history
  • Loading branch information
oischinger committed Oct 2, 2022
1 parent 0afdfa9 commit a26a46d
Show file tree
Hide file tree
Showing 29 changed files with 631 additions and 13 deletions.
8 changes: 8 additions & 0 deletions custom_components/vicare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ class ViCareRequiredKeysMixin:
value_getter: Callable[[Device], bool]


@dataclass()
class ViCareRequiredKeysMixinWithSet:
"""Mixin for required keys with setter."""

value_getter: Callable[[Device], bool]
value_setter: Callable[[Device], bool]


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up from config entry."""
_LOGGER.debug("Setting up ViCare component")
Expand Down
43 changes: 34 additions & 9 deletions custom_components/vicare/button.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Viessmann ViCare sensor device."""
"""Viessmann ViCare button device."""
from __future__ import annotations

from contextlib import suppress
Expand All @@ -18,7 +18,7 @@
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import ViCareRequiredKeysMixin
from . import ViCareRequiredKeysMixinWithSet
from .const import DOMAIN, VICARE_API, VICARE_DEVICE_CONFIG, VICARE_NAME

_LOGGER = logging.getLogger(__name__)
Expand All @@ -27,8 +27,10 @@


@dataclass
class ViCareButtonEntityDescription(ButtonEntityDescription, ViCareRequiredKeysMixin):
"""Describes ViCare button sensor entity."""
class ViCareButtonEntityDescription(
ButtonEntityDescription, ViCareRequiredKeysMixinWithSet
):
"""Describes ViCare button entity."""


BUTTON_DESCRIPTIONS: tuple[ViCareButtonEntityDescription, ...] = (
Expand All @@ -37,24 +39,47 @@ class ViCareButtonEntityDescription(ButtonEntityDescription, ViCareRequiredKeysM
name="Activate one-time charge",
icon="mdi:shower-head",
entity_category=EntityCategory.CONFIG,
value_getter=lambda api: api.activateOneTimeCharge(),
value_getter=lambda api: api.getOneTimeCharge(),
value_setter=lambda api: api.activateOneTimeCharge(),
),
)


def _build_entity(name, vicare_api, device_config, description):
"""Create a ViCare button entity."""
_LOGGER.debug("Found device %s", name)
try:
description.value_getter(vicare_api)
_LOGGER.debug("Found entity %s", name)
except PyViCareNotSupportedFeatureError:
_LOGGER.info("Feature not supported %s", name)
return None
except AttributeError:
_LOGGER.debug("Attribute Error %s", name)
return None

return ViCareButton(
name,
vicare_api,
device_config,
description,
)


async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Create the ViCare binary sensor devices."""
"""Create the ViCare button entities."""
name = VICARE_NAME
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]

entities = []

for description in BUTTON_DESCRIPTIONS:
entity = ViCareButton(
entity = await hass.async_add_executor_job(
_build_entity,
f"{name} {description.name}",
api,
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
Expand All @@ -74,7 +99,7 @@ class ViCareButton(ButtonEntity):
def __init__(
self, name, api, device_config, description: ViCareButtonEntityDescription
):
"""Initialize the sensor."""
"""Initialize the button."""
self.entity_description = description
self._device_config = device_config
self._api = api
Expand All @@ -83,7 +108,7 @@ def press(self) -> None:
"""Handle the button press."""
try:
with suppress(PyViCareNotSupportedFeatureError):
self.entity_description.value_getter(self._api)
self.entity_description.value_setter(self._api)
except requests.exceptions.ConnectionError:
_LOGGER.error("Unable to retrieve data from ViCare server")
except ValueError:
Expand Down
4 changes: 2 additions & 2 deletions custom_components/vicare/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import requests
import voluptuous as vol

from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import (
from homeassistant.components.climate import (
PRESET_COMFORT,
PRESET_ECO,
PRESET_NONE,
ClimateEntity,
ClimateEntityFeature,
HVACAction,
HVACMode,
Expand Down
64 changes: 64 additions & 0 deletions custom_components/vicare/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,38 @@ class ViCareSensorEntityDescription(SensorEntityDescription, ViCareRequiredKeysM
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
),
ViCareSensorEntityDescription(
key="primary_circuit_supply_temperature",
name="Primary Circuit Supply Temperature",
native_unit_of_measurement=TEMP_CELSIUS,
value_getter=lambda api: api.getSupplyTemperaturePrimaryCircuit(),
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
),
ViCareSensorEntityDescription(
key="primary_circuit_return_temperature",
name="Primary Circuit Return Temperature",
native_unit_of_measurement=TEMP_CELSIUS,
value_getter=lambda api: api.getReturnTemperaturePrimaryCircuit(),
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
),
ViCareSensorEntityDescription(
key="secondary_circuit_supply_temperature",
name="Secondary Circuit Supply Temperature",
native_unit_of_measurement=TEMP_CELSIUS,
value_getter=lambda api: api.getSupplyTemperatureSecondaryCircuit(),
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
),
ViCareSensorEntityDescription(
key="secondary_circuit_return_temperature",
name="Secondary Circuit Return Temperature",
native_unit_of_measurement=TEMP_CELSIUS,
value_getter=lambda api: api.getReturnTemperatureSecondaryCircuit(),
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
),
ViCareSensorEntityDescription(
key="hotwater_out_temperature",
name="Hot Water Out Temperature",
Expand All @@ -94,6 +126,22 @@ class ViCareSensorEntityDescription(SensorEntityDescription, ViCareRequiredKeysM
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
),
ViCareSensorEntityDescription(
key="hotwater_max_temperature",
name="Hot Water Max Temperature",
native_unit_of_measurement=TEMP_CELSIUS,
value_getter=lambda api: api.getDomesticHotWaterMaxTemperature(),
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
),
ViCareSensorEntityDescription(
key="hotwater_min_temperature",
name="Hot Water Min Temperature",
native_unit_of_measurement=TEMP_CELSIUS,
value_getter=lambda api: api.getDomesticHotWaterMinTemperature(),
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
),
ViCareSensorEntityDescription(
key="hotwater_gas_consumption_today",
name="Hot water gas consumption today",
Expand Down Expand Up @@ -398,6 +446,22 @@ class ViCareSensorEntityDescription(SensorEntityDescription, ViCareRequiredKeysM
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
ViCareSensorEntityDescription(
key="buffer top temperature",
name="Buffer Top Temperature",
native_unit_of_measurement=TEMP_CELSIUS,
value_getter=lambda api: api.getBufferTopTemperature(),
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
),
ViCareSensorEntityDescription(
key="buffer main temperature",
name="Buffer Main Temperature",
native_unit_of_measurement=TEMP_CELSIUS,
value_getter=lambda api: api.getBufferMainTemperature(),
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
),
)

CIRCUIT_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
Expand Down
12 changes: 12 additions & 0 deletions custom_components/vicare/translations/af.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"config": {
"step": {
"user": {
"data": {
"password": "\u5bc6\u7801",
"username": "\u7535\u5b50\u90ae\u7bb1"
}
}
}
}
}
21 changes: 21 additions & 0 deletions custom_components/vicare/translations/bg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"config": {
"abort": {
"single_instance_allowed": "\u0412\u0435\u0447\u0435 \u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0430\u043d\u043e. \u0412\u044a\u0437\u043c\u043e\u0436\u043d\u0430 \u0435 \u0441\u0430\u043c\u043e \u0435\u0434\u043d\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f.",
"unknown": "\u041d\u0435\u043e\u0447\u0430\u043a\u0432\u0430\u043d\u0430 \u0433\u0440\u0435\u0448\u043a\u0430"
},
"error": {
"invalid_auth": "\u041d\u0435\u0432\u0430\u043b\u0438\u0434\u043d\u043e \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u044f\u0432\u0430\u043d\u0435"
},
"flow_title": "{name} ({host})",
"step": {
"user": {
"data": {
"client_id": "API \u043a\u043b\u044e\u0447",
"password": "\u041f\u0430\u0440\u043e\u043b\u0430",
"username": "Email"
}
}
}
}
}
23 changes: 23 additions & 0 deletions custom_components/vicare/translations/ca.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"config": {
"abort": {
"single_instance_allowed": "Ja configurat. Nom\u00e9s \u00e9s possible una sola configuraci\u00f3.",
"unknown": "Error inesperat"
},
"error": {
"invalid_auth": "Autenticaci\u00f3 inv\u00e0lida"
},
"flow_title": "{name} ({host})",
"step": {
"user": {
"data": {
"client_id": "Clau API",
"heating_type": "Tipus d'escalfador",
"password": "Contrasenya",
"username": "Correu electr\u00f2nic"
},
"description": "Configura la integraci\u00f3 ViCare. Per generar la clau API, v\u00e9s a https://developer.viessmann.com"
}
}
}
}
21 changes: 21 additions & 0 deletions custom_components/vicare/translations/cs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"config": {
"abort": {
"single_instance_allowed": "Ji\u017e nastaveno. Je mo\u017en\u00e1 pouze jedin\u00e1 konfigurace.",
"unknown": "Neo\u010dek\u00e1van\u00e1 chyba"
},
"error": {
"invalid_auth": "Neplatn\u00e9 ov\u011b\u0159en\u00ed"
},
"flow_title": "{name} ({host})",
"step": {
"user": {
"data": {
"client_id": "Kl\u00ed\u010d API",
"password": "Heslo",
"username": "E-mail"
}
}
}
}
}
23 changes: 23 additions & 0 deletions custom_components/vicare/translations/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"config": {
"abort": {
"single_instance_allowed": "Bereits konfiguriert. Nur eine einzige Konfiguration m\u00f6glich.",
"unknown": "Unerwarteter Fehler"
},
"error": {
"invalid_auth": "Ung\u00fcltige Authentifizierung"
},
"flow_title": "{name} ({host})",
"step": {
"user": {
"data": {
"client_id": "API-Schl\u00fcssel",
"heating_type": "Art der Heizung",
"password": "Passwort",
"username": "E-Mail"
},
"description": "Richte die ViCare-Integration ein. Um einen API-Schl\u00fcssel zu generieren, gehe auf https://developer.viessmann.com"
}
}
}
}
23 changes: 23 additions & 0 deletions custom_components/vicare/translations/el.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"config": {
"abort": {
"single_instance_allowed": "\u0388\u03c7\u03b5\u03b9 \u03ae\u03b4\u03b7 \u03c1\u03c5\u03b8\u03bc\u03b9\u03c3\u03c4\u03b5\u03af. \u039c\u03cc\u03bd\u03bf \u03bc\u03af\u03b1 \u03b4\u03b9\u03b1\u03bc\u03cc\u03c1\u03c6\u03c9\u03c3\u03b7 \u03b5\u03af\u03bd\u03b1\u03b9 \u03b4\u03c5\u03bd\u03b1\u03c4\u03ae.",
"unknown": "\u0391\u03c0\u03c1\u03cc\u03c3\u03bc\u03b5\u03bd\u03bf \u03c3\u03c6\u03ac\u03bb\u03bc\u03b1"
},
"error": {
"invalid_auth": "\u039c\u03b7 \u03ad\u03b3\u03ba\u03c5\u03c1\u03bf\u03c2 \u03ad\u03bb\u03b5\u03b3\u03c7\u03bf\u03c2 \u03c4\u03b1\u03c5\u03c4\u03cc\u03c4\u03b7\u03c4\u03b1\u03c2"
},
"flow_title": "{name} ({host})",
"step": {
"user": {
"data": {
"client_id": "\u039a\u03bb\u03b5\u03b9\u03b4\u03af API",
"heating_type": "\u03a4\u03cd\u03c0\u03bf\u03c2 \u03b8\u03ad\u03c1\u03bc\u03b1\u03bd\u03c3\u03b7\u03c2",
"password": "\u039a\u03c9\u03b4\u03b9\u03ba\u03cc\u03c2 \u03c0\u03c1\u03cc\u03c3\u03b2\u03b1\u03c3\u03b7\u03c2",
"username": "Email"
},
"description": "\u03a1\u03c5\u03b8\u03bc\u03af\u03c3\u03c4\u03b5 \u03c4\u03b7\u03bd \u03b5\u03bd\u03c3\u03c9\u03bc\u03ac\u03c4\u03c9\u03c3\u03b7 \u03c4\u03bf\u03c5 ViCare. \u0393\u03b9\u03b1 \u03bd\u03b1 \u03b4\u03b7\u03bc\u03b9\u03bf\u03c5\u03c1\u03b3\u03ae\u03c3\u03b5\u03c4\u03b5 \u03c4\u03bf \u03ba\u03bb\u03b5\u03b9\u03b4\u03af API \u03bc\u03b5\u03c4\u03b1\u03b2\u03b5\u03af\u03c4\u03b5 \u03c3\u03c4\u03b7 \u03b4\u03b9\u03b5\u03cd\u03b8\u03c5\u03bd\u03c3\u03b7 https://developer.viessmann.com"
}
}
}
}
3 changes: 1 addition & 2 deletions custom_components/vicare/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"password": "Password",
"username": "Email"
},
"description": "Setup ViCare to control your Viessmann device.\nMinimum needed: username, password, API key.",
"title": "Setup ViCare"
"description": "Set up ViCare integration. To generate API key go to https://developer.viessmann.com"
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions custom_components/vicare/translations/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"config": {
"abort": {
"single_instance_allowed": "Ya est\u00e1 configurado. Solo es posible una \u00fanica configuraci\u00f3n.",
"unknown": "Error inesperado"
},
"error": {
"invalid_auth": "Autenticaci\u00f3n no v\u00e1lida"
},
"flow_title": "{name} ({host})",
"step": {
"user": {
"data": {
"client_id": "Clave API",
"heating_type": "Tipo de calefacci\u00f3n",
"password": "Contrase\u00f1a",
"username": "Correo electr\u00f3nico"
},
"description": "Configura la integraci\u00f3n de ViCare. Para generar la clave API, ve a https://developer.viessmann.com"
}
}
}
}
Loading

0 comments on commit a26a46d

Please sign in to comment.