Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update select.py for AIR_OUTSIDE_TPT #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion select.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.components.sensor import SensorEntity

from .const import DOMAIN, PRODUCT_COORDINATORS
from .entity import AldesProductDataUpdateCoordinator, AldesProductEntity

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback) -> None:
coordinators = hass.data[DOMAIN][entry.entry_id][PRODUCT_COORDINATORS]
async_add_entities(AldesProductEntityModeSelect(coordinator) for coordinator in coordinators)

async_add_entities(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create another async_setup_entry in the new sensor.py file.

[
AldesProductEntityModeSelect(coordinator) for coordinator in coordinators
] + [
AldesProductOutsideTempSensor(coordinator) for coordinator in coordinators # Aggiungi il sensore per la temperatura esterna
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sensor is not supported by all the products in https://github.com/aalmazanarbs/hassio_aldes/blob/master/aldes/product.py#L20, please, make it conditional and invoke async_add_entities if the product support it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, change code comments to english.

]
)

class AldesProductEntityModeSelect(AldesProductEntity, SelectEntity):

Expand All @@ -29,3 +37,20 @@ def current_option(self) -> str:
async def async_select_option(self, option: str) -> None:
await self.coordinator.product.maybe_set_mode_from_display(option)
await self.coordinator.async_request_refresh()


# Nuova classe per il sensore della temperatura esterna (AIR_OUTSIDE_TPT)
class AldesProductOutsideTempSensor(AldesProductEntity, SensorEntity):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, move this class and its async_setup_entry to a different class. Something like sensor.py.


_attr_icon = "mdi:thermometer"

def __init__(self, coordinator: AldesProductDataUpdateCoordinator) -> None:
super().__init__(coordinator, 'Outside Air Temperature')

@property
def native_value(self):
return self.coordinator.product.air_outside_tpt # Restituisce il valore della temperatura esterna
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this code comment, self explanatory with native_value.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

air_outside_tpt is not present in AldesProduct, you must provide a way to get this value.


@property
def native_unit_of_measurement(self):
return "°C"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it always °C? or it is configurable by Aldes App? If it is always in °C ok, but take care of because °F is also other possible value