From d378c4d0da3d50b34b3324cb346df5286e041082 Mon Sep 17 00:00:00 2001 From: Johan Isacsson Date: Fri, 22 Oct 2021 14:59:06 +0200 Subject: [PATCH] Adds support for setting device priority --- custom_components/myenergi/const.py | 2 +- custom_components/myenergi/manifest.json | 4 +-- custom_components/myenergi/number.py | 43 ++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/custom_components/myenergi/const.py b/custom_components/myenergi/const.py index 36f7523..a5ab3cc 100644 --- a/custom_components/myenergi/const.py +++ b/custom_components/myenergi/const.py @@ -3,7 +3,7 @@ NAME = "myenergi" DOMAIN = "myenergi" DOMAIN_DATA = f"{DOMAIN}_data" -VERSION = "0.0.14" +VERSION = "0.0.16" ATTRIBUTION = "Data provided by myenergi" ISSUE_URL = "https://github.com/cjne/myenergi/issues" diff --git a/custom_components/myenergi/manifest.json b/custom_components/myenergi/manifest.json index acbe0f6..df71d69 100644 --- a/custom_components/myenergi/manifest.json +++ b/custom_components/myenergi/manifest.json @@ -1,12 +1,12 @@ { "domain": "myenergi", "name": "myenergi", - "version": "0.0.15", + "version": "0.0.16", "documentation": "https://github.com/cjne/ha-myenergi", "issue_tracker": "https://github.com/cjne/ha-myenergi/issues", "dependencies": [], "config_flow": true, "codeowners": ["@cjne"], "iot_class": "cloud_polling", - "requirements": ["pymyenergi==0.0.23"] + "requirements": ["pymyenergi==0.0.24"] } diff --git a/custom_components/myenergi/number.py b/custom_components/myenergi/number.py index 4f22885..79f5767 100644 --- a/custom_components/myenergi/number.py +++ b/custom_components/myenergi/number.py @@ -15,8 +15,10 @@ async def async_setup_entry(hass, entry, async_add_devices): # Zappi only numbers if device.kind == "zappi": devices.append(MinimumGreenLevelNumber(coordinator, device, entry)) + devices.append(DevicePriorityNumber(coordinator, device, entry)) elif device.kind == "eddi": devices.append(HeaterPriorityNumber(coordinator, device, entry)) + devices.append(DevicePriorityNumber(coordinator, device, entry)) async_add_devices(devices) @@ -61,6 +63,47 @@ def step(self): return 1 +class DevicePriorityNumber(MyenergiEntity, NumberEntity): + """myenergi number class.""" + + def __init__(self, coordinator, device, config_entry): + super().__init__(coordinator, device, config_entry) + + @property + def unique_id(self): + """Return a unique ID to use for this entity.""" + return ( + f"{self.config_entry.entry_id}-{self.device.serial_number}-device_priority" + ) + + @property + def name(self): + """Return the name of the sensor.""" + return f"myenergi {self.device.name} Device Priority" + + @property + def value(self): + """Return the state of the sensor.""" + return self.device.priority + + async def async_set_value(self, value: float) -> None: + """Change the selected option.""" + await self.device.set_priority(int(value)) + self.async_schedule_update_ha_state() + + @property + def min_value(self): + return 1 + + @property + def max_value(self): + return 10 + + @property + def step(self): + return 1 + + class MinimumGreenLevelNumber(MyenergiEntity, NumberEntity): """myenergi Sensor class."""