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

Divide dialogs for thermostat #110

Merged
merged 4 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
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
44 changes: 30 additions & 14 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
TIMEOUT = 10


def _get_nice_number(number: str) -> str:
"""Convert number to nice formated number"""
try:
return nice_number(float(number))
except TypeError:
return number
except ValueError:
return number


# pylint: disable=R0912, W0105, W0511, W0233
class HomeAssistantSkill(FallbackSkill):
"""Main skill class"""
Expand Down Expand Up @@ -471,7 +481,7 @@ def _handle_open_close_actions(self, message: Message) -> None:
return

ha_entity = self._find_entity(entity, ['cover'])
# Exit if entity not found or is unavailabe
# Exit if entity not found or is unavailable
if not ha_entity or not self._check_availability(ha_entity):
return

Expand Down Expand Up @@ -626,7 +636,23 @@ def _handle_automation(self, message: Message) -> None:
self.ha_client.execute_service("scene", "turn_on",
data=ha_data)

def _handle_sensor(self, message: Message) -> None:
def _dialog_sensor_climate(self, name: str, state: str, attr: dict) -> None:
"""Handle dialogs for sensor climate."""
current_temp = _get_nice_number(attr['current_temperature'])
target_temp = _get_nice_number(attr['temperature'])
if current_temp:
self.speak_dialog('homeassistant.sensor.thermostat.current', data={
"dev_name": name,
"value": state,
"current_temp": current_temp,
"targeted_temp": target_temp})
else:
self.speak_dialog('homeassistant.sensor.thermostat', data={
"dev_name": name,
"value": state,
"targeted_temp": target_temp})

def _handle_sensor(self, message) -> None:
"""Handler sensors reading"""
entity = message.data["Entity"]
self.log.debug("Entity: %s", entity)
Expand Down Expand Up @@ -670,20 +696,10 @@ def _handle_sensor(self, message: Message) -> None:
sensor_unit = quantity.unit.name
sensor_state = quantity.value

try:
value = float(sensor_state)
sensor_state = nice_number(value, lang=self.language)
except ValueError:
pass
sensor_state = _get_nice_number(sensor_state)

if domain == "climate" and sensor_state != '':
current_temp = nice_number((float(attributes['current_temperature'])))
target_temp = nice_number((float(attributes['temperature'])))
self.speak_dialog('homeassistant.sensor.thermostat', data={
"dev_name": sensor_name,
"value": sensor_state,
"current_temp": current_temp,
"targeted_temp": target_temp})
self._dialog_sensor_climate(sensor_name, sensor_state, attributes)

self._display_sensor_dialog(
sensor_name,
Expand Down
3 changes: 3 additions & 0 deletions dialog/cs-cz/homeassistant.sensor.thermostat.current.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Momentálně je režim {dev_name} {value}, současná teplota je {current_temp} a nastavená {targeted_temp}.
Režim {dev_name} je {value}, současná teplota je {current_temp} a nastavená {targeted_temp}.
{dev_name} je {value}, aktuální teplota je {current_temp} a nastavená {targeted_temp}.
6 changes: 3 additions & 3 deletions dialog/cs-cz/homeassistant.sensor.thermostat.dialog
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Momentálně je režim {dev_name} {value}, současná teplota je {current_temp} a nastavená {targeted_temp}.
Režim {dev_name} je {value}, současná teplota je {current_temp} a nastavená {targeted_temp}.
{dev_name} je {value}, aktuální teplota je {current_temp} a nastavená {targeted_temp}.
Momentálně je režim {dev_name} {value}, cílová teplota je nastavená na {targeted_temp}.
Režim {dev_name} je {value}, cílová teplota nastavená na {targeted_temp}.
{dev_name} je {value}, cílová teplota je nastavená na {targeted_temp}.
3 changes: 3 additions & 0 deletions dialog/de-de/homeassistant.sensor.thermostat.current.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Der aktuelle Status von {dev_name} ist {value}, die aktuelle Temperatur ist {current_temp} und die Zieltemperatur {targeted_temp}.
{dev_name} Status ist {value}, die aktuelle Temperatur ist {current_temp} und die Zieltemperatur {targeted_temp}.
{dev_name} ist {value}, Temperatur ist {current_temp} und auf {targeted_temp} eingestellt.
6 changes: 3 additions & 3 deletions dialog/de-de/homeassistant.sensor.thermostat.dialog
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Der aktuelle Status von {dev_name} ist {value}, die aktuelle Temperatur ist {current_temp} und die Zieltemperatur {targeted_temp}.
{dev_name} Status ist {value}, die aktuelle Temperatur ist {current_temp} und die Zieltemperatur {targeted_temp}.
{dev_name} ist {value}, Temperatur ist {current_temp} und auf {targeted_temp} eingestellt.
Der aktuelle Status von {dev_name} ist {value}, die aktuelle Zieltemperatur ist {targeted_temp}.
{dev_name} Status ist {value}, die Zieltemperatur ist {targeted_temp}.
{dev_name} ist {value} und die Zieltemperatur ist auf {targeted_temp} eingestellt.
3 changes: 3 additions & 0 deletions dialog/en-us/homeassistant.sensor.thermostat.current.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Currently {dev_name} mode is {value}, current temperature is {current_temp} and targeted {targeted_temp}.
{dev_name} mode is {value}, current temperature is {current_temp} and targeted {targeted_temp}.
{dev_name} is {value}, temperature is {current_temp} and set to {targeted_temp}.
6 changes: 3 additions & 3 deletions dialog/en-us/homeassistant.sensor.thermostat.dialog
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Currently {dev_name} mode is {value}, current temperature is {current_temp} and targeted {targeted_temp}.
{dev_name} mode is {value}, current temperature is {current_temp} and targeted {targeted_temp}.
{dev_name} is {value}, temperature is {current_temp} and set to {targeted_temp}.
Currently {dev_name} mode is {value}, current targeted temperature is {targeted_temp}.
{dev_name} mode is {value}, targeted temperature is {targeted_temp}.
{dev_name} is {value}, temperature is set to {targeted_temp}.
9 changes: 7 additions & 2 deletions test/behave/01_sensor.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
@allure.suite:behave
Feature: sensor
Feature: Get sensor state
@xfail
Scenario: read sensor
Scenario: default sensor
Given an English speaking user
When the user says "give me the value of Mycroft sensor please"
Then mycroft reply should contain "122"
@xfail
Scenario: climate sensor
Given an English speaking user
When the user says "give me the value of Mycroft climate please"
Then "homeassistant" should reply with dialog from "homeassistant.sensor.thermostat.dialog"