Skip to content

Commit

Permalink
Add sensor platform to eq3btsmart
Browse files Browse the repository at this point in the history
  • Loading branch information
EuleMitKeule committed Nov 14, 2024
1 parent 3db4d95 commit f2fb30a
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 1 deletion.
1 change: 1 addition & 0 deletions homeassistant/components/eq3btsmart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
Platform.BINARY_SENSOR,
Platform.CLIMATE,
Platform.NUMBER,
Platform.SENSOR,
Platform.SWITCH,
]

Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/eq3btsmart/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
ENTITY_KEY_OFFSET = "offset"
ENTITY_KEY_WINDOW_OPEN_TEMPERATURE = "window_open_temperature"
ENTITY_KEY_WINDOW_OPEN_TIMEOUT = "window_open_timeout"
ENTITY_KEY_VALVE = "valve"
ENTITY_KEY_AWAY_UNTIL = "away_until"

GET_DEVICE_TIMEOUT = 5 # seconds

Expand Down
10 changes: 9 additions & 1 deletion homeassistant/components/eq3btsmart/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,19 @@
"default": "mdi:timer-refresh"
}
},
"sensor": {
"away_until": {
"default": "mdi:home-export-outline"
},
"valve": {
"default": "mdi:pipe-valve"
}
},
"switch": {
"away": {
"default": "mdi:home-account",
"state": {
"on": "mdi:home-export"
"on": "mdi:home-export-outline"
}
},
"lock": {
Expand Down
86 changes: 86 additions & 0 deletions homeassistant/components/eq3btsmart/sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"""Platform for eq3 sensor entities."""

from collections.abc import Callable
from dataclasses import dataclass
from datetime import date, datetime
from decimal import Decimal
from typing import TYPE_CHECKING

Check warning on line 7 in homeassistant/components/eq3btsmart/sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/eq3btsmart/sensor.py#L3-L7

Added lines #L3 - L7 were not covered by tests

from eq3btsmart.models import Status

Check warning on line 9 in homeassistant/components/eq3btsmart/sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/eq3btsmart/sensor.py#L9

Added line #L9 was not covered by tests

from homeassistant.components.sensor import (

Check warning on line 11 in homeassistant/components/eq3btsmart/sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/eq3btsmart/sensor.py#L11

Added line #L11 was not covered by tests
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
StateType,
)
from homeassistant.components.sensor.const import SensorStateClass
from homeassistant.const import PERCENTAGE
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

Check warning on line 20 in homeassistant/components/eq3btsmart/sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/eq3btsmart/sensor.py#L17-L20

Added lines #L17 - L20 were not covered by tests

from . import Eq3ConfigEntry
from .const import ENTITY_KEY_AWAY_UNTIL, ENTITY_KEY_VALVE
from .entity import Eq3Entity

Check warning on line 24 in homeassistant/components/eq3btsmart/sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/eq3btsmart/sensor.py#L22-L24

Added lines #L22 - L24 were not covered by tests


@dataclass(frozen=True, kw_only=True)
class Eq3SensorEntityDescription(SensorEntityDescription):

Check warning on line 28 in homeassistant/components/eq3btsmart/sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/eq3btsmart/sensor.py#L27-L28

Added lines #L27 - L28 were not covered by tests
"""Entity description for eq3 sensor entities."""

value_func: Callable[[Status], StateType | date | datetime | Decimal]

Check warning on line 31 in homeassistant/components/eq3btsmart/sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/eq3btsmart/sensor.py#L31

Added line #L31 was not covered by tests


SENSOR_ENTITY_DESCRIPTIONS = [

Check warning on line 34 in homeassistant/components/eq3btsmart/sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/eq3btsmart/sensor.py#L34

Added line #L34 was not covered by tests
Eq3SensorEntityDescription(
key=ENTITY_KEY_VALVE,
translation_key=ENTITY_KEY_VALVE,
value_func=lambda status: status.valve,
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
),
Eq3SensorEntityDescription(
key=ENTITY_KEY_AWAY_UNTIL,
translation_key=ENTITY_KEY_AWAY_UNTIL,
value_func=lambda status: status.away_until.value
if status.away_until
else None,
device_class=SensorDeviceClass.DATE,
),
]


async def async_setup_entry(

Check warning on line 53 in homeassistant/components/eq3btsmart/sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/eq3btsmart/sensor.py#L53

Added line #L53 was not covered by tests
hass: HomeAssistant,
entry: Eq3ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the entry."""

async_add_entities(

Check warning on line 60 in homeassistant/components/eq3btsmart/sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/eq3btsmart/sensor.py#L60

Added line #L60 was not covered by tests
Eq3SensorEntity(entry, entity_description)
for entity_description in SENSOR_ENTITY_DESCRIPTIONS
)


class Eq3SensorEntity(Eq3Entity, SensorEntity):

Check warning on line 66 in homeassistant/components/eq3btsmart/sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/eq3btsmart/sensor.py#L66

Added line #L66 was not covered by tests
"""Base class for eq3 sensor entities."""

entity_description: Eq3SensorEntityDescription

Check warning on line 69 in homeassistant/components/eq3btsmart/sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/eq3btsmart/sensor.py#L69

Added line #L69 was not covered by tests

def __init__(

Check warning on line 71 in homeassistant/components/eq3btsmart/sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/eq3btsmart/sensor.py#L71

Added line #L71 was not covered by tests
self, entry: Eq3ConfigEntry, entity_description: Eq3SensorEntityDescription
) -> None:
"""Initialize the entity."""

super().__init__(entry, entity_description.key)
self.entity_description = entity_description

Check warning on line 77 in homeassistant/components/eq3btsmart/sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/eq3btsmart/sensor.py#L76-L77

Added lines #L76 - L77 were not covered by tests

@property
def native_value(self) -> StateType | date | datetime | Decimal:

Check warning on line 80 in homeassistant/components/eq3btsmart/sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/eq3btsmart/sensor.py#L79-L80

Added lines #L79 - L80 were not covered by tests
"""Return the value reported by the sensor."""

if TYPE_CHECKING:
assert self._thermostat.status is not None

return self.entity_description.value_func(self._thermostat.status)

Check warning on line 86 in homeassistant/components/eq3btsmart/sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/eq3btsmart/sensor.py#L86

Added line #L86 was not covered by tests
8 changes: 8 additions & 0 deletions homeassistant/components/eq3btsmart/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
"name": "Window open timeout"
}
},
"sensor": {
"away_until": {
"name": "Away until"
},
"valve": {
"name": "Valve"
}
},
"switch": {
"lock": {
"name": "Lock"
Expand Down

0 comments on commit f2fb30a

Please sign in to comment.