-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from mattjgalloway/pv_divert_updates
PV diverter updates
- Loading branch information
Showing
6 changed files
with
250 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from .const import DOMAIN | ||
from .tank import Tank | ||
from homeassistant.helpers.update_coordinator import CoordinatorEntity | ||
|
||
class MixergyEntityBase(CoordinatorEntity): | ||
|
||
should_poll = True | ||
|
||
def __init__(self, coordinator, tank:Tank): | ||
super().__init__(coordinator) | ||
self._tank = tank | ||
|
||
@property | ||
def device_info(self): | ||
return { | ||
"identifiers": {(DOMAIN, self._tank.serial_number)}, | ||
"manufacturer": "Mixergy Ltd", | ||
"name": "Mixergy Tank", | ||
"suggested_area": "garage", | ||
"model": self._tank.modelCode, | ||
"sw_version": self._tank.firmwareVersion | ||
} | ||
|
||
@property | ||
def available(self) -> bool: | ||
return self._tank.online | ||
|
||
async def async_added_to_hass(self): | ||
self._tank.register_callback(self.async_write_ha_state) | ||
|
||
async def async_will_remove_from_hass(self): | ||
self._tank.remove_callback(self.async_write_ha_state) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import logging | ||
from homeassistant.components.number import NumberEntity | ||
from .const import DOMAIN | ||
from .tank import Tank | ||
from .mixergy_entity import MixergyEntityBase | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
async def async_setup_entry(hass, config_entry, async_add_entities): | ||
_LOGGER.info("Setting up entry based on user config") | ||
|
||
entry = hass.data[DOMAIN][config_entry.entry_id] | ||
tank = entry["tank"] | ||
coordinator = entry["coordinator"] | ||
|
||
new_entities = [] | ||
|
||
new_entities.append(PVChargeLimitSensor(coordinator, tank)) | ||
|
||
async_add_entities(new_entities) | ||
|
||
class NumberEntityBase(MixergyEntityBase, NumberEntity): | ||
|
||
def __init__(self, coordinator, tank:Tank): | ||
super().__init__(coordinator, tank) | ||
|
||
class PVChargeLimitSensor(NumberEntityBase): | ||
|
||
native_max_value = 100 | ||
native_min_value = 0 | ||
native_step = 10 | ||
|
||
def __init__(self, coordinator, tank:Tank): | ||
super().__init__( coordinator, tank) | ||
|
||
@property | ||
def unique_id(self): | ||
return f"mixergy_{self._tank.tank_id}_pv_charge_limit" | ||
|
||
@property | ||
def state(self): | ||
return self._tank.pv_charge_limit | ||
|
||
@property | ||
def available(self): | ||
return super().available and self._tank.has_pv_diverter | ||
|
||
async def async_set_native_value(self, value: float): | ||
await self._tank.set_pv_charge_limit(int(value)) | ||
|
||
@property | ||
def icon(self): | ||
return "mdi:lightning-bolt" | ||
|
||
@property | ||
def name(self): | ||
return f"PV Charge Limit" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import logging | ||
from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity | ||
from .const import DOMAIN | ||
from .tank import Tank | ||
from .mixergy_entity import MixergyEntityBase | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
async def async_setup_entry(hass, config_entry, async_add_entities): | ||
_LOGGER.info("Setting up entry based on user config") | ||
|
||
entry = hass.data[DOMAIN][config_entry.entry_id] | ||
tank = entry["tank"] | ||
coordinator = entry["coordinator"] | ||
|
||
new_entities = [] | ||
|
||
new_entities.append(PVDivertSwitch(coordinator, tank)) | ||
|
||
async_add_entities(new_entities) | ||
|
||
class SwitchEntityBase(MixergyEntityBase, SwitchEntity): | ||
|
||
device_class = SwitchDeviceClass.SWITCH | ||
|
||
def __init__(self, coordinator, tank:Tank): | ||
super().__init__(coordinator, tank) | ||
|
||
class PVDivertSwitch(SwitchEntityBase): | ||
|
||
def __init__(self, coordinator, tank:Tank): | ||
super().__init__(coordinator, tank) | ||
|
||
@property | ||
def unique_id(self): | ||
return f"mixergy_{self._tank.tank_id}_pv_divert_enabled" | ||
|
||
@property | ||
def name(self): | ||
return f"PV Divert Enabled" | ||
|
||
@property | ||
def available(self): | ||
return super().available and self._tank.has_pv_diverter | ||
|
||
@property | ||
def is_on(self): | ||
return self._tank.divert_exported_enabled | ||
|
||
async def async_turn_on(self, **kwargs): | ||
await self._tank.set_divert_exported_enabled(True) | ||
|
||
async def async_turn_off(self, **kwargs): | ||
await self._tank.set_divert_exported_enabled(False) |
Oops, something went wrong.