Skip to content

Commit a138345

Browse files
committed
sensor: add weatherTemp for #37
Signed-off-by: Vladimir Ermakov <vooon341@gmail.com>
1 parent fd1961e commit a138345

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

custom_components/myheat/binary_sensor.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Binary sensor platform for MyHeat."""
22

33
from itertools import chain
4-
import logging
54

65
from homeassistant.components.binary_sensor import BinarySensorEntity
76
from homeassistant.config_entries import ConfigEntry
@@ -11,8 +10,6 @@
1110
from .const import DOMAIN
1211
from .entity import MhEngEntity, MhEntity, MhEnvEntity, MhHeaterEntity
1312

14-
_logger = logging.getLogger(__package__)
15-
1613

1714
async def async_setup_entry(
1815
hass: HomeAssistant,

custom_components/myheat/climate.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Climate platform for MyHeat."""
22

3-
import logging
4-
53
from homeassistant.components.climate import (
64
PRESET_AWAY,
75
PRESET_ECO,
@@ -24,7 +22,6 @@
2422
from .const import DOMAIN
2523
from .entity import MhEnvEntity
2624

27-
_logger = logging.getLogger(__package__)
2825

2926
PRESET_TO_ID = {
3027
# PRESET_ACTIVITY: 0,
@@ -46,8 +43,6 @@ async def async_setup_entry(
4643
"""Setup climate platform."""
4744
coordinator = hass.data[DOMAIN][entry.entry_id]
4845

49-
_logger.info(f"Setting up env entries: {coordinator.data}")
50-
5146
async_add_entities(
5247
[
5348
MhEnvClimate(coordinator, entry, env)

custom_components/myheat/sensor.py

+32-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
"""Sensor platform for MyHeat."""
22

33
from itertools import chain
4-
import logging
54

65
from homeassistant.components.sensor import SensorEntity
76
from homeassistant.config_entries import ConfigEntry
87
from homeassistant.const import UnitOfTemperature
98
from homeassistant.core import HomeAssistant
109
from homeassistant.helpers.entity_platform import AddEntitiesCallback
1110

12-
from .const import CONF_NAME, DEFAULT_NAME, DOMAIN
11+
from .const import DOMAIN
1312
from .entity import MhHeaterEntity, MhEntity
1413

15-
_logger = logging.getLogger(__package__)
16-
1714

1815
async def async_setup_entry(
1916
hass: HomeAssistant,
@@ -23,9 +20,8 @@ async def async_setup_entry(
2320
"""Setup sensor platform."""
2421
coordinator = hass.data[DOMAIN][entry.entry_id]
2522

26-
_logger.info(f"Setting up heater entries: {coordinator.data}")
27-
28-
async_add_entities(
23+
entities = chain(
24+
(MhWeatherTempSensor(coordinator, entry),),
2925
chain.from_iterable(
3026
[
3127
MhHeaterFlowTempSensor(coordinator, entry, heater),
@@ -35,13 +31,39 @@ async def async_setup_entry(
3531
MhHeaterModulationSensor(coordinator, entry, heater),
3632
]
3733
for heater in coordinator.data.get("heaters", [])
38-
)
34+
),
3935
)
4036

37+
async_add_entities(entities)
4138

42-
class MhHeaterSensor(MhHeaterEntity, SensorEntity):
43-
"""myheat Sensor class."""
4439

40+
class MhWeatherTempSensor(MhEntity, SensorEntity):
41+
"""myheat weatherTemp Sensor class."""
42+
43+
_attr_device_class = "temperature"
44+
_attr_unit_of_measurement = UnitOfTemperature.CELSIUS
45+
46+
@property
47+
def name(self) -> str:
48+
return f"{self._mh_name} weatherTemp"
49+
50+
@property
51+
def unique_id(self):
52+
return f"{super().unique_id}weatherTemp"
53+
54+
@property
55+
def state(self):
56+
return self.coordinator.data.get("weatherTemp")
57+
58+
@property
59+
def extra_state_attributes(self):
60+
city = self.coordinator.data.get("city")
61+
return {
62+
"city": city,
63+
}
64+
65+
66+
class MhHeaterSensor(MhHeaterEntity, SensorEntity):
4567
@property
4668
def state(self):
4769
"""Return the state of the sensor."""

0 commit comments

Comments
 (0)