Skip to content

Commit

Permalink
feat: Inverted property for binary_sensor platform
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Aug 16, 2024
1 parent 585358d commit 08d530d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion custom_components/solarman/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ async def async_unload_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:
class SolarmanBinarySensorEntity(SolarmanEntity, BinarySensorEntity):
def __init__(self, coordinator, sensor):
SolarmanEntity.__init__(self, coordinator, _PLATFORM, sensor)
self._sensor_inverted = False

if "inverted" in sensor and (inverted := sensor["inverted"]):
self._sensor_inverted = inverted

@property
def is_on(self) -> bool | None:
return self._attr_state != 0
return (self._attr_state != 0) if not self._sensor_inverted else (self._attr_state == 0)

class SolarmanConnectionSensor(SolarmanBinarySensorEntity):
def __init__(self, coordinator, sensor):
Expand Down

0 comments on commit 08d530d

Please sign in to comment.