Skip to content

Commit

Permalink
add voltage meter user query
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenKelevra committed Dec 19, 2024
1 parent 4a42905 commit f2cc9f5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions utils/measure/.env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@ MYSTROM_DEVICE_IP=x.x.x.x
# MODEL_NAME=xx
# DUMMY_LOAD=true
# POWERMETER_ENTITY_ID=sensor.my_power
# VOLTAGEMETER_ENTITY_ID=sensor.my_voltage
# RESUME=true
1 change: 1 addition & 0 deletions utils/measure/measure/powermeter/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PowerMeterType(str, Enum):


QUESTION_POWERMETER_ENTITY_ID = "powermeter_entity_id"
QUESTION_VOLTAGEMETER_ENTITY_ID = "voltagemeter_entity_id"


class Trend(StrEnum):
Expand Down
17 changes: 16 additions & 1 deletion utils/measure/measure/powermeter/hass.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import inquirer
from homeassistant_api import Client

from measure.powermeter.const import QUESTION_POWERMETER_ENTITY_ID
from measure.powermeter.const import QUESTION_POWERMETER_ENTITY_ID, QUESTION_VOLTAGEMETER_ENTITY_ID
from measure.powermeter.errors import PowerMeterError, UnsupportedFeatureError
from measure.powermeter.powermeter import PowerMeasurementResult, PowerMeter

Expand Down Expand Up @@ -66,8 +66,22 @@ def has_voltage_support(self) -> bool:
def find_voltage_entity(self) -> str | None:
"""Try to find a matching voltage entity for the current power entity."""
matched_sensors = self.match_power_and_voltage_sensors()

if not matched_sensors:
return self.get_voltage_question(self.get_voltage_sensors())

return matched_sensors.get(self._entity_id)

def get_voltage_question(self, voltage_sensor_list: list[str]) -> str | None:

Check notice on line 75 in utils/measure/measure/powermeter/hass.py

View workflow job for this annotation

GitHub Actions / qodana

Method is not declared static

Method `get_voltage_question` may be 'static'
"""Return a question to select a voltage sensor."""
return [
inquirer.List(
name=QUESTION_VOLTAGEMETER_ENTITY_ID,
message="Select the voltage sensor",
choices=voltage_sensor_list,
)
]

def get_questions(self) -> list[inquirer.questions.Question]:
power_sensor_list = self.get_power_sensors()

Expand Down Expand Up @@ -108,3 +122,4 @@ def match_power_and_voltage_sensors(self) -> dict[str, str]:

def process_answers(self, answers: dict[str, Any]) -> None:
self._entity_id = answers[QUESTION_POWERMETER_ENTITY_ID]
self._voltage_entity_id = answers[QUESTION_VOLTAGEMETER_ENTITY_ID]

0 comments on commit f2cc9f5

Please sign in to comment.