Skip to content

Commit

Permalink
binary_sensor implementation copied from ha default
Browse files Browse the repository at this point in the history
  • Loading branch information
ThermIQ committed Jan 8, 2024
1 parent ade16e3 commit d78103c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 21 deletions.
18 changes: 9 additions & 9 deletions ThermIQ_Card.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ entities:
@keyframes blink { to {visibility: hidden;}}
</style>
<div style="height:330px;width:100%;{% if (states('binary_sensor.thermiq_mqtt_vp1_alarm_indication_on')=='True') %}background-color:red;{% endif %}">
<div style="height:330px;width:100%;{% if (states('binary_sensor.thermiq_mqtt_vp1_alarm_indication_on')=='on') %}background-color:red;{% endif %}">
<div style="position:absolute;left:130px;">
{% if states('binary_sensor.thermiq_mqtt_vp1_hotwaterproduction_on')=='True' %}
{% if states('binary_sensor.thermiq_mqtt_vp1_hotwaterproduction_on')=='on' %}
<div><img class="hp_basepict hw" style="position:absolute;top:0px;left:0px;height:300px;" alt="vp missing" src="/local/community/vp_base_hw.jpg" title=""></div>
{% else %}
{% if (states('binary_sensor.thermiq_mqtt_vp1_opt_hgw_installed')=='True') and (states('binary_sensor.thermiq_mqtt_vp1_compressor_on')=='True') %}
{% if (states('binary_sensor.thermiq_mqtt_vp1_opt_hgw_installed')=='on') and (states('binary_sensor.thermiq_mqtt_vp1_compressor_on')=='on') %}
<div><img class="hp_basepict hgw" style="position:absolute;top:0px;left:0px;height:300px;" alt="vp missing" src="/local/community/vp_base_hgwon.jpg" title=""></div>
{% else %}
<div><img class="hp_basepict base active" style="position:absolute;top:0px;left:0px;height:300px;" alt="vp missing" src="/local/community/vp_base.jpg" title="ThermIQ"></div>
Expand All @@ -39,14 +39,14 @@ entities:
<div class="hpwidget-val" title="Boiler Temperature" style="position:absolute;top:89px;left:138px;z-index:3;"><span class="hpwidget-name-span" id="hpwidget-T_VATTEN"></span>{{ states('sensor.thermiq_mqtt_vp1_boiler_t') }}<span class="hpwidget-unit-span">&nbsp;C</span></div>
<div class="hpwidget-val" title="HGW Temperature" style="position:absolute;top:87px;left:76px;z-index:3; <span class="hpwidget-name-span" id="hpwidget-HGW_VV"></span>{{ states('sensor.thermiq_mqtt_vp1_hgw_water_t') }}<span class="hpwidget-unit-span">&nbsp;C</span></div>
<div class="hpwidget-val" title="Supply-line Temperature" style="position:absolute;top:131px;left:138px;z-index:3;"><span class="hpwidget-name-span" id="hpwidget-T_FRAM"></span>{{ states('sensor.thermiq_mqtt_vp1_supplyline_t') }}<span class="hpwidget-unit-span">&nbsp;C</span></div>
<div class="hpwidget-val" title="Supply pump" style="position:absolute;top:257px;left:146px;z-index:3;{% if (states('binary_sensor.thermiq_mqtt_vp1_opt_optimum_installed')=='False') %}display:none;{% endif %}"><span class="hpwidget-name-span" id="hpwidget-CIRK_SPEED"></span>{{ states('sensor.thermiq_mqtt_vp1_supply_pump_speed') }}<span class="hpwidget-unit-span">&nbsp;%</span></div>
<div class="hpwidget-val" title="Brine pump" style="position:absolute;top:156px;left:8px;z-index:3;{% if (states('binary_sensor.thermiq_mqtt_vp1_opt_optimum_installed')=='False') %}display:none;{% endif %}"><span class="hpwidget-name-span" id="hpwidget-BRINE_SPEED"></span>{{ states('sensor.thermiq_mqtt_vp1_brine_pump_speed') }}<span class="hpwidget-unit-span">&nbsp;%</span></div>
<div class="hpwidget-val" title="Supply pump" style="position:absolute;top:257px;left:146px;z-index:3;{% if (states('binary_sensor.thermiq_mqtt_vp1_opt_optimum_installed')=='off') %}display:none;{% endif %}"><span class="hpwidget-name-span" id="hpwidget-CIRK_SPEED"></span>{{ states('sensor.thermiq_mqtt_vp1_supply_pump_speed') }}<span class="hpwidget-unit-span">&nbsp;%</span></div>
<div class="hpwidget-val" title="Brine pump" style="position:absolute;top:156px;left:8px;z-index:3;{% if (states('binary_sensor.thermiq_mqtt_vp1_opt_optimum_installed')=='off') %}display:none;{% endif %}"><span class="hpwidget-name-span" id="hpwidget-BRINE_SPEED"></span>{{ states('sensor.thermiq_mqtt_vp1_brine_pump_speed') }}<span class="hpwidget-unit-span">&nbsp;%</span></div>
<div class="hpwidget-val" title="Return line Temperature" style="position:absolute;top:200px;left:146px;z-index:3;"><span class="hpwidget-name-span" id="hpwidget-T_RETUR"></span>{{ states('sensor.thermiq_mqtt_vp1_returnline_t') }}<span class="hpwidget-unit-span">&nbsp;C</span></div>
<div class="hpwidget-val" title="Pressure pipe Temperature" style="position:absolute;top:125px;left:76px;z-index:3;"><span class="hpwidget-name-span" id="hpwidget-TRYCKR_T"></span>{{ states('sensor.thermiq_mqtt_vp1_pressurepipe_t') }}<span class="hpwidget-unit-span">&nbsp;C</span></div>
<ha-icon icon="mdi:flash" id="hpwidget-ELEFF" style="color:yellow;position:absolute;top:42px;left:82px;z-index:2;{% if ((states('binary_sensor.thermiq_mqtt_vp1_boiler_3kw_on')=='False') and (states('binary_sensor.thermiq_mqtt_vp1_boiler_6kw_on')=='False') ) %}display:none{% endif %}"></ha-icon>
<ha-icon icon="mdi:cog" id="hpwidget-KOMPR" style="position:absolute;top:155px;left:70px;--mdc-icon-size:45px;z-index:2;{% if (states('binary_sensor.thermiq_mqtt_vp1_compressor_on')=='True') %}animation: rotating 2s linear infinite;{% endif %}"></ha-icon>
<ha-icon icon="mdi:fan" id="hpwidget-BRINESPIN" style="position:absolute;top:126px;left:11px;z-index:2;{% if (states('binary_sensor.thermiq_mqtt_vp1_brine_pump_on')=='True') %}animation: rotating 2s linear infinite;{% endif %}"></ha-icon>
<ha-icon icon="mdi:fan" id="hpwidget-CIRKPSPIN" style="position:absolute;top:228px;left:147px;z-index:2;{% if (states('binary_sensor.thermiq_mqtt_vp1_supply_pump_on')=='True') %}animation: rotating 2s linear infinite;{% endif %}"></ha-icon>
<ha-icon icon="mdi:flash" id="hpwidget-ELEFF" style="color:yellow;position:absolute;top:42px;left:82px;z-index:2;{% if ((states('binary_sensor.thermiq_mqtt_vp1_boiler_3kw_on')=='off') and (states('binary_sensor.thermiq_mqtt_vp1_boiler_6kw_on')=='off') ) %}display:none{% endif %}"></ha-icon>
<ha-icon icon="mdi:cog" id="hpwidget-KOMPR" style="position:absolute;top:155px;left:70px;--mdc-icon-size:45px;z-index:2;{% if (states('binary_sensor.thermiq_mqtt_vp1_compressor_on')=='on') %}animation: rotating 2s linear infinite;{% endif %}"></ha-icon>
<ha-icon icon="mdi:fan" id="hpwidget-BRINESPIN" style="position:absolute;top:126px;left:11px;z-index:2;{% if (states('binary_sensor.thermiq_mqtt_vp1_brine_pump_on')=='on') %}animation: rotating 2s linear infinite;{% endif %}"></ha-icon>
<ha-icon icon="mdi:fan" id="hpwidget-CIRKPSPIN" style="position:absolute;top:228px;left:147px;z-index:2;{% if (states('binary_sensor.thermiq_mqtt_vp1_supply_pump_on')=='on') %}animation: rotating 2s linear infinite;{% endif %}"></ha-icon>
<ha-icon icon="mdi:alert-circle" id="hpwidget-ALERT" style="color:red;position:absolute;top:42px;left:82px;z-index:4;animation: blink 1s steps(5, start) infinite;{% if (states('sensor.thermiq_mqtt_vp1_communication_status')=='Ok') %}display:none{% endif %}"></ha-icon>
<ha-icon icon="mdi:stop" id="hpwidget-EVU" style="color:red;position:absolute;top:62px;left:82px;z-index:120;animation: blink 1s steps(5, start) infinite;{% if (states('sensor.thermiq_mqtt_vp1_heatpump_evu_block') | int ==0) %}display:none{% endif %}">EVU</ha-icon>
</div>
Expand Down
28 changes: 21 additions & 7 deletions custom_components/thermiq_mqtt/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import logging
from typing import TYPE_CHECKING, Literal, final
from homeassistant.core import HomeAssistant, callback

from homeassistant.const import STATE_OFF, STATE_ON

from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.const import (
ATTR_IDENTIFIERS,
ATTR_MANUFACTURER,
ATTR_MODEL,
ATTR_NAME,
)
STATE_OFF,
STATE_ON,
EntityCategory)

from homeassistant.helpers.device_registry import DeviceEntryType

from homeassistant.const import (
Expand All @@ -31,6 +39,11 @@
reg_id,
)

if TYPE_CHECKING:
from functools import cached_property
else:
from homeassistant.backports.functools import cached_property

_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -130,19 +143,20 @@ def should_poll(self):
"""No need to poll. Coordinator notifies entity of updates."""
return False

@final
@property
def state(self):
def state(self) -> Literal["on", "off"]:
"""Return the state of the sensor."""
return True if (self._state) else False
return STATE_ON if (self._state) else STATE_OFF

@property
def vp_reg(self):
"""Return the device class of the sensor."""
return self._vp_reg

@property
def is_on(self):
return STATE_ON if (self._state) else STATE_OFF
@cached_property
def is_on(self) -> bool:
return (self._state==True)

@property
def sorter(self):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/thermiq_mqtt/heatpump/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ async def update_config(self, entry):
self._set_topic = self._mqtt_base + "set"
self._hpstate["mqtt_counter"] = 0

# Provide some debug info
# Provide some debug info
_LOGGER.debug(
f"INFO: {self._domain}_{self._id} mqtt_node: [{entry.data[CONF_MQTT_NODE]}]"
)
Expand Down
4 changes: 2 additions & 2 deletions custom_components/thermiq_mqtt/input_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
CONF_MODE,
CONF_NAME,
CONF_UNIT_OF_MEASUREMENT,
TEMP_CELSIUS,
UnitOfTemperature,
)
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_platform import EntityPlatform
Expand Down Expand Up @@ -120,7 +120,7 @@ def create_input_number_entity(heatpump, name) -> CustomInputNumber:
]
):
icon = "mdi:temperature-celsius"
unit = TEMP_CELSIUS
unit = UnitOfTemperature.CELSIUS
else:
unit = reg_id[name][2]
icon = "mdi:gauge"
Expand Down
4 changes: 2 additions & 2 deletions custom_components/thermiq_mqtt/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from homeassistant.helpers.entity import Entity, async_generate_entity_id

from homeassistant.const import (
TEMP_CELSIUS,
UnitOfTemperature,
PERCENTAGE
)

Expand Down Expand Up @@ -126,7 +126,7 @@ def __init__(
]
):
self._icon = "mdi:temperature-celsius"
self._unit =TEMP_CELSIUS
self._unit =UnitOfTemperature.CELSIUS
elif vp_type in [
"sensor_boolean",
]:
Expand Down

0 comments on commit d78103c

Please sign in to comment.