Skip to content

Commit

Permalink
Adds support for setting device priority
Browse files Browse the repository at this point in the history
  • Loading branch information
CJNE committed Oct 22, 2021
1 parent 794972d commit d378c4d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion custom_components/myenergi/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions custom_components/myenergi/manifest.json
Original file line number Diff line number Diff line change
@@ -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"]
}
43 changes: 43 additions & 0 deletions custom_components/myenergi/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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."""

Expand Down

0 comments on commit d378c4d

Please sign in to comment.