Skip to content

Commit

Permalink
Run formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jul 30, 2022
1 parent 07a7385 commit 50529a5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions custom_components/powercalc/sensors/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,17 @@ def on_state_change(self, event):
# Maybe we will convert these units in the future
for state in available_states:
unit_of_measurement = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
if unit_of_measurement is None: # No unit of measurement, probably sensor has been reset
if (
unit_of_measurement is None
): # No unit of measurement, probably sensor has been reset
continue
if unit_of_measurement != self._attr_native_unit_of_measurement:
_LOGGER.error(
f"Group member '{state.entity_id}' has another unit of measurement '{unit_of_measurement}' than the group '{self.entity_id}' which has '{self._attr_native_unit_of_measurement}', this is not supported yet. Removing this entity from the total sum."
)
available_states.remove(state)
self._entities.remove(state.entity_id)

if not available_states:
self._attr_available = False
self.async_schedule_update_ha_state(True)
Expand Down
3 changes: 2 additions & 1 deletion tests/sensors/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ async def test_mega_watt_hour(hass: HomeAssistant):

assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_MEGA_WATT_HOUR


async def test_group_unavailable_when_members_unavailable(hass: HomeAssistant):
await create_input_booleans(hass, ["test1", "test2"])

Expand All @@ -322,4 +323,4 @@ async def test_group_unavailable_when_members_unavailable(hass: HomeAssistant):
assert power_state.state == STATE_UNAVAILABLE

energy_state = hass.states.get("sensor.testgroup_power")
assert energy_state.state == STATE_UNAVAILABLE
assert energy_state.state == STATE_UNAVAILABLE

0 comments on commit 50529a5

Please sign in to comment.