Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codechimp committed Apr 9, 2024
1 parent e5efc96 commit 2fea27a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
23 changes: 21 additions & 2 deletions custom_components/hive_mqtt_orchestrator/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback
):
"""Set up the sensor platform."""

_entities = {}

hive_climate_entity_description = HiveClimateEntityDescription(
Expand All @@ -74,15 +75,14 @@ async def async_setup_entry(
_entities = [HiveClimateEntity(entity_description=hive_climate_entity_description) ]

async_add_entities(
[climateEntity for climateEntity in _entities],
climateEntity for climateEntity in _entities
)

hass.data[DOMAIN][config_entry.entry_id][Platform.CLIMATE] = _entities

class HiveClimateEntity(HiveEntity, ClimateEntity):
"""hive_mqtt_orchestrator Climate class."""


def __init__(
self,
entity_description: HiveClimateEntityDescription,
Expand Down Expand Up @@ -120,6 +120,8 @@ def __init__(

@property
def hvac_mode(self):
"""Get the current hvac mode."""

if not self._mqtt_data:
return

Expand All @@ -133,6 +135,8 @@ def hvac_mode(self):
return HVACMode.OFF

async def async_set_hvac_mode(self, hvac_mode):
"""Set the hvac mode."""

if hvac_mode in self._attr_hvac_modes:
self._attr_hvac_mode = hvac_mode
else:
Expand Down Expand Up @@ -171,6 +175,8 @@ async def async_set_hvac_mode(self, hvac_mode):

@property
def hvac_action(self):
"""Get the current action."""

if not self._mqtt_data:
return

Expand All @@ -185,13 +191,17 @@ def hvac_action(self):

@property
def current_temperature(self):
"""Get the current temperature."""

if not self._mqtt_data:
return
if "local_temperature_heat" in self._mqtt_data:
return self._mqtt_data["local_temperature_heat"]

@property
def target_temperature(self):
"""Get the target temperature."""

if not self._mqtt_data:
return
if "occupied_heating_setpoint_heat" in self._mqtt_data:
Expand All @@ -200,22 +210,30 @@ def target_temperature(self):
return self._mqtt_data["occupied_heating_setpoint_heat"]

async def async_set_temperature(self, temperature, **kwargs):
"""Set the target temperature."""

payload = r'{"occupied_heating_setpoint_heat":' + str(temperature) + r'}'

LOGGER.debug("Sending to {self._topic}/set message {payload}")
await mqtt_client.async_publish(self.hass, self._topic + "/set", payload)

def _climate_preset(self, mode):
"""Get the current preset."""

return next((k for k, v in PRESET_MAP.items() if v == mode), PRESET_MAP[PRESET_NONE])

@property
def preset_mode(self):
"""Get the preset mode."""

if not self._mqtt_data:
return
if "system_mode_heat" in self._mqtt_data:
return self._climate_preset(self._mqtt_data["system_mode_heat"])

async def async_set_preset_mode(self, preset_mode):
"""Set the preset mode."""

if preset_mode == "boost":
self._pre_boost_hvac_mode = self.hvac_mode
self._pre_boost_occupied_heating_setpoint_heat = self.target_temperature
Expand All @@ -231,6 +249,7 @@ async def async_set_preset_mode(self, preset_mode):

def process_update(self, mqtt_data) -> None:
"""Update the state of the sensor."""

self._mqtt_data = mqtt_data
if (self.hass is not None): # this is a hack to get around the fact that the entity is not yet initialized at first
self.async_schedule_update_ha_state()
2 changes: 1 addition & 1 deletion custom_components/hive_mqtt_orchestrator/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async def async_setup_entry(
_entities = [HiveNumber(entity_description=entity_description,) for entity_description in entity_descriptions]

async_add_entities(
[sensorEntity for sensorEntity in _entities],
sensorEntity for sensorEntity in _entities
)

hass.data[DOMAIN][config_entry.entry_id][Platform.NUMBER] = _entities
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hive_mqtt_orchestrator/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async def async_setup_entry(
_entities = [HiveSelect(entity_description=entity_description,) for entity_description in ENTITY_DESCRIPTIONS]

async_add_entities(
[sensorEntity for sensorEntity in _entities],
sensorEntity for sensorEntity in _entities
)

hass.data[DOMAIN][config_entry.entry_id][Platform.SELECT] = _entities
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hive_mqtt_orchestrator/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async def async_setup_entry(
_entities = [HiveSensor(entity_description=entity_description,) for entity_description in entity_descriptions]

async_add_entities(
[sensorEntity for sensorEntity in _entities],
sensorEntity for sensorEntity in _entities
)

hass.data[DOMAIN][config_entry.entry_id][Platform.SENSOR] = _entities
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hive_mqtt_orchestrator/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async def async_setup_entry(
_entities = [HiveSwitch(entity_description=entity_description,) for entity_description in entity_descriptions]

async_add_entities(
[sensorEntity for sensorEntity in _entities],
sensorEntity for sensorEntity in _entities
)

hass.data[DOMAIN][config_entry.entry_id][Platform.SWITCH] = _entities
Expand Down

0 comments on commit 2fea27a

Please sign in to comment.