-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Electricity Metering module
- Loading branch information
1 parent
3da4610
commit f8bfe50
Showing
13 changed files
with
376 additions
and
48 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
48 changes: 48 additions & 0 deletions
48
custom_components/nhc2/entities/electricity_clamp_centralmeter_clamp_type.py
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,48 @@ | ||
from homeassistant.components.sensor import SensorEntity, SensorDeviceClass | ||
from homeassistant.helpers.entity import EntityCategory | ||
|
||
from ..const import DOMAIN, BRAND | ||
|
||
from ..nhccoco.devices.electricity_clamp_centralmeter import CocoElectricityClampCentralmeter | ||
|
||
|
||
class Nhc2ElectricityClampCentralmeterClampTypeEntity(SensorEntity): | ||
_attr_has_entity_name = True | ||
|
||
def __init__(self, device_instance: CocoElectricityClampCentralmeter, hub, gateway): | ||
"""Initialize a binary sensor.""" | ||
self._device = device_instance | ||
self._hub = hub | ||
self._gateway = gateway | ||
|
||
self._device.after_change_callbacks.append(self.on_change) | ||
|
||
self._attr_available = self._device.is_online | ||
self._attr_unique_id = device_instance.uuid + '_clamp_type' | ||
self._attr_should_poll = False | ||
|
||
self._attr_device_class = SensorDeviceClass.ENUM | ||
self._attr_options = self._device.possible_clamp_types | ||
self._attr_native_value = self._device.clamp_type | ||
self._attr_state_class = None | ||
self._attr_entity_category = EntityCategory.DIAGNOSTIC | ||
|
||
@property | ||
def name(self) -> str: | ||
return 'Electricity Metering Module Segment' | ||
|
||
@property | ||
def device_info(self): | ||
"""Return the device info.""" | ||
return { | ||
'identifiers': { | ||
(DOMAIN, self._device.uuid) | ||
}, | ||
'name': self._device.name, | ||
'manufacturer': BRAND, | ||
'model': str.title(f'{self._device.model} ({self._device.type})'), | ||
'via_device': self._hub | ||
} | ||
|
||
def on_change(self): | ||
self.schedule_update_ha_state() |
50 changes: 50 additions & 0 deletions
50
custom_components/nhc2/entities/electricity_clamp_centralmeter_electrical_power.py
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,50 @@ | ||
from homeassistant.components.sensor import SensorEntity, SensorDeviceClass, SensorStateClass | ||
from homeassistant.const import UnitOfPower | ||
|
||
from ..const import DOMAIN, BRAND | ||
|
||
from ..nhccoco.devices.electricity_clamp_centralmeter import CocoElectricityClampCentralmeter | ||
|
||
class Nhc2ElectricityClampCentralmeterElectricalPowerEntity(SensorEntity): | ||
_attr_has_entity_name = True | ||
|
||
def __init__(self, device_instance: CocoElectricityClampCentralmeter, hub, gateway): | ||
"""Initialize a binary sensor.""" | ||
self._device = device_instance | ||
self._hub = hub | ||
self._gateway = gateway | ||
|
||
self._device.after_change_callbacks.append(self.on_change) | ||
|
||
self._attr_available = self._device.is_online | ||
self._attr_unique_id = device_instance.uuid + '_electrical_power' | ||
self._attr_should_poll = False | ||
|
||
self._attr_device_class = SensorDeviceClass.POWER | ||
self._attr_native_value = self._device.electrical_power | ||
self._attr_native_unit_of_measurement = UnitOfPower.WATT | ||
self._attr_state_class = SensorStateClass.MEASUREMENT | ||
|
||
@property | ||
def name(self) -> str: | ||
return 'Electrical Power' | ||
|
||
@property | ||
def device_info(self): | ||
"""Return the device info.""" | ||
return { | ||
'identifiers': { | ||
(DOMAIN, self._device.uuid) | ||
}, | ||
'name': self._device.name, | ||
'manufacturer': BRAND, | ||
'model': str.title(f'{self._device.model} ({self._device.type})'), | ||
'via_device': self._hub | ||
} | ||
|
||
@property | ||
def state(self) -> float: | ||
return self._device.electrical_power | ||
|
||
def on_change(self): | ||
self.schedule_update_ha_state() |
48 changes: 48 additions & 0 deletions
48
custom_components/nhc2/entities/electricity_clamp_centralmeter_flow.py
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,48 @@ | ||
from homeassistant.components.sensor import SensorEntity, SensorDeviceClass | ||
from homeassistant.helpers.entity import EntityCategory | ||
|
||
from ..const import DOMAIN, BRAND | ||
|
||
from ..nhccoco.devices.electricity_clamp_centralmeter import CocoElectricityClampCentralmeter | ||
|
||
|
||
class Nhc2ElectricityClampCentralmeterFlowEntity(SensorEntity): | ||
_attr_has_entity_name = True | ||
|
||
def __init__(self, device_instance: CocoElectricityClampCentralmeter, hub, gateway): | ||
"""Initialize a binary sensor.""" | ||
self._device = device_instance | ||
self._hub = hub | ||
self._gateway = gateway | ||
|
||
self._device.after_change_callbacks.append(self.on_change) | ||
|
||
self._attr_available = self._device.is_online | ||
self._attr_unique_id = device_instance.uuid + '_flow' | ||
self._attr_should_poll = False | ||
|
||
self._attr_device_class = SensorDeviceClass.ENUM | ||
self._attr_options = self._device.possible_flows | ||
self._attr_native_value = self._device.flow | ||
self._attr_state_class = None | ||
self._attr_entity_category = EntityCategory.DIAGNOSTIC | ||
|
||
@property | ||
def name(self) -> str: | ||
return 'Electricity Metering Module Flow' | ||
|
||
@property | ||
def device_info(self): | ||
"""Return the device info.""" | ||
return { | ||
'identifiers': { | ||
(DOMAIN, self._device.uuid) | ||
}, | ||
'name': self._device.name, | ||
'manufacturer': BRAND, | ||
'model': str.title(f'{self._device.model} ({self._device.type})'), | ||
'via_device': self._hub | ||
} | ||
|
||
def on_change(self): | ||
self.schedule_update_ha_state() |
59 changes: 59 additions & 0 deletions
59
custom_components/nhc2/entities/electricity_clamp_centralmeter_report_instant_usage.py
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,59 @@ | ||
from homeassistant.components.binary_sensor import BinarySensorEntity | ||
from homeassistant.helpers.entity import EntityCategory | ||
|
||
from ..const import DOMAIN, BRAND | ||
|
||
from ..nhccoco.devices.electricity_clamp_centralmeter import CocoElectricityClampCentralmeter | ||
|
||
import logging | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class Nhc2ElectricityClampCentralmeterReportInstantUsageEntity(BinarySensorEntity): | ||
_attr_has_entity_name = True | ||
|
||
def __init__(self, device_instance: CocoElectricityClampCentralmeter, hub, gateway): | ||
"""Initialize a binary sensor.""" | ||
self._device = device_instance | ||
self._hub = hub | ||
self._gateway = gateway | ||
|
||
self._device.after_change_callbacks.append(self.on_change) | ||
|
||
self._attr_available = self._device.is_online | ||
self._attr_unique_id = device_instance.uuid + '_report_instant_usage' | ||
self._attr_should_poll = False | ||
|
||
self._attr_state = self._device.is_report_instant_usage | ||
self._attr_state_class = None | ||
self._attr_entity_category = EntityCategory.DIAGNOSTIC | ||
|
||
@property | ||
def name(self) -> str: | ||
return 'Report Instant Usage' | ||
|
||
@property | ||
def device_info(self): | ||
"""Return the device info.""" | ||
return { | ||
'identifiers': { | ||
(DOMAIN, self._device.uuid) | ||
}, | ||
'name': self._device.name, | ||
'manufacturer': BRAND, | ||
'model': str.title(f'{self._device.model} ({self._device.type})'), | ||
'via_device': self._hub | ||
} | ||
|
||
@property | ||
def is_on(self) -> bool: | ||
return self._device.is_report_instant_usage | ||
|
||
def on_change(self): | ||
# Re-enable reporting when it is turned off | ||
if self._device.is_report_instant_usage is False: | ||
_LOGGER.debug(f'{self.name} re-enabled') | ||
self._device.enable_report_instant_usage(self._gateway) | ||
|
||
self.schedule_update_ha_state() |
48 changes: 48 additions & 0 deletions
48
custom_components/nhc2/entities/electricity_clamp_centralmeter_segment.py
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,48 @@ | ||
from homeassistant.components.sensor import SensorEntity, SensorDeviceClass | ||
from homeassistant.helpers.entity import EntityCategory | ||
|
||
from ..const import DOMAIN, BRAND | ||
|
||
from ..nhccoco.devices.electricity_clamp_centralmeter import CocoElectricityClampCentralmeter | ||
|
||
|
||
class Nhc2ElectricityClampCentralmeterSegmentEntity(SensorEntity): | ||
_attr_has_entity_name = True | ||
|
||
def __init__(self, device_instance: CocoElectricityClampCentralmeter, hub, gateway): | ||
"""Initialize a binary sensor.""" | ||
self._device = device_instance | ||
self._hub = hub | ||
self._gateway = gateway | ||
|
||
self._device.after_change_callbacks.append(self.on_change) | ||
|
||
self._attr_available = self._device.is_online | ||
self._attr_unique_id = device_instance.uuid + '_segment' | ||
self._attr_should_poll = False | ||
|
||
self._attr_device_class = SensorDeviceClass.ENUM | ||
self._attr_options = self._device.possible_segments | ||
self._attr_native_value = self._device.segment | ||
self._attr_state_class = None | ||
self._attr_entity_category = EntityCategory.DIAGNOSTIC | ||
|
||
@property | ||
def name(self) -> str: | ||
return 'Electricity Metering Module Segment' | ||
|
||
@property | ||
def device_info(self): | ||
"""Return the device info.""" | ||
return { | ||
'identifiers': { | ||
(DOMAIN, self._device.uuid) | ||
}, | ||
'name': self._device.name, | ||
'manufacturer': BRAND, | ||
'model': str.title(f'{self._device.model} ({self._device.type})'), | ||
'via_device': self._hub | ||
} | ||
|
||
def on_change(self): | ||
self.schedule_update_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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.