core/homeassistant/components/powerwall/sensor.py

191 lines
5.6 KiB
Python
Raw Normal View History

Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
"""Support for August sensors."""
import logging
from tesla_powerwall import MeterType
from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
SensorEntity,
)
from homeassistant.const import (
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER,
ENERGY_KILO_WATT_HOUR,
PERCENTAGE,
POWER_KILO_WATT,
)
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
from .const import (
ATTR_FREQUENCY,
ATTR_INSTANT_AVERAGE_VOLTAGE,
ATTR_INSTANT_TOTAL_CURRENT,
ATTR_IS_ACTIVE,
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
DOMAIN,
POWERWALL_API_CHARGE,
POWERWALL_API_DEVICE_TYPE,
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
POWERWALL_API_METERS,
POWERWALL_API_SERIAL_NUMBERS,
POWERWALL_API_SITE_INFO,
POWERWALL_API_STATUS,
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
POWERWALL_COORDINATOR,
)
from .entity import PowerWallEntity
_METER_DIRECTION_EXPORT = "export"
_METER_DIRECTION_IMPORT = "import"
_METER_DIRECTIONS = [_METER_DIRECTION_EXPORT, _METER_DIRECTION_IMPORT]
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the August sensors."""
powerwall_data = hass.data[DOMAIN][config_entry.entry_id]
_LOGGER.debug("Powerwall_data: %s", powerwall_data)
coordinator = powerwall_data[POWERWALL_COORDINATOR]
site_info = powerwall_data[POWERWALL_API_SITE_INFO]
device_type = powerwall_data[POWERWALL_API_DEVICE_TYPE]
status = powerwall_data[POWERWALL_API_STATUS]
powerwalls_serial_numbers = powerwall_data[POWERWALL_API_SERIAL_NUMBERS]
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
entities = []
for meter in MeterType:
entities.append(
PowerWallEnergySensor(
meter,
coordinator,
site_info,
status,
device_type,
powerwalls_serial_numbers,
)
)
for meter_direction in _METER_DIRECTIONS:
entities.append(
PowerWallEnergyDirectionSensor(
meter,
coordinator,
site_info,
status,
device_type,
powerwalls_serial_numbers,
meter_direction,
)
)
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
entities.append(
PowerWallChargeSensor(
coordinator, site_info, status, device_type, powerwalls_serial_numbers
)
)
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
async_add_entities(entities, True)
class PowerWallChargeSensor(PowerWallEntity, SensorEntity):
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
"""Representation of an Powerwall charge sensor."""
2021-06-23 06:19:02 +00:00
_attr_name = "Powerwall Charge"
_attr_native_unit_of_measurement = PERCENTAGE
2021-06-23 06:19:02 +00:00
_attr_device_class = DEVICE_CLASS_BATTERY
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
@property
def unique_id(self):
"""Device Uniqueid."""
return f"{self.base_unique_id}_charge"
@property
def native_value(self):
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
"""Get the current value in percentage."""
return round(self.coordinator.data[POWERWALL_API_CHARGE])
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
class PowerWallEnergySensor(PowerWallEntity, SensorEntity):
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
"""Representation of an Powerwall Energy sensor."""
2021-06-23 06:19:02 +00:00
_attr_state_class = STATE_CLASS_MEASUREMENT
_attr_native_unit_of_measurement = POWER_KILO_WATT
2021-06-23 06:19:02 +00:00
_attr_device_class = DEVICE_CLASS_POWER
def __init__(
self,
meter: MeterType,
coordinator,
site_info,
status,
device_type,
powerwalls_serial_numbers,
):
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
"""Initialize the sensor."""
super().__init__(
coordinator, site_info, status, device_type, powerwalls_serial_numbers
)
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
self._meter = meter
2021-06-23 06:19:02 +00:00
self._attr_name = f"Powerwall {self._meter.value.title()} Now"
self._attr_unique_id = (
f"{self.base_unique_id}_{self._meter.value}_instant_power"
)
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
@property
def native_value(self):
"""Get the current value in kW."""
return (
self.coordinator.data[POWERWALL_API_METERS]
.get_meter(self._meter)
.get_power(precision=3)
)
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
@property
def extra_state_attributes(self):
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
"""Return the device specific state attributes."""
meter = self.coordinator.data[POWERWALL_API_METERS].get_meter(self._meter)
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
return {
ATTR_FREQUENCY: round(meter.frequency, 1),
ATTR_INSTANT_AVERAGE_VOLTAGE: round(meter.average_voltage, 1),
ATTR_INSTANT_TOTAL_CURRENT: meter.get_instant_total_current(),
ATTR_IS_ACTIVE: meter.is_active(),
Add Powerwalls integration (#32851) * Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-19 15:50:17 +00:00
}
class PowerWallEnergyDirectionSensor(PowerWallEntity, SensorEntity):
"""Representation of an Powerwall Direction Energy sensor."""
_attr_state_class = STATE_CLASS_TOTAL_INCREASING
_attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR
_attr_device_class = DEVICE_CLASS_ENERGY
def __init__(
self,
meter: MeterType,
coordinator,
site_info,
status,
device_type,
powerwalls_serial_numbers,
meter_direction,
):
"""Initialize the sensor."""
super().__init__(
coordinator, site_info, status, device_type, powerwalls_serial_numbers
)
self._meter = meter
self._meter_direction = meter_direction
self._attr_name = (
f"Powerwall {self._meter.value.title()} {self._meter_direction.title()}"
)
self._attr_unique_id = (
f"{self.base_unique_id}_{self._meter.value}_{self._meter_direction}"
)
@property
def native_value(self):
"""Get the current value in kWh."""
meter = self.coordinator.data[POWERWALL_API_METERS].get_meter(self._meter)
if self._meter_direction == _METER_DIRECTION_EXPORT:
return meter.get_energy_exported()
return meter.get_energy_imported()