Skip to content

Commit

Permalink
remove commented code
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeneef committed Sep 29, 2024
1 parent 5b51978 commit 5dee0e7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 56 deletions.
3 changes: 2 additions & 1 deletion custom_components/gpiod/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def async_setup_platform(
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None) -> None:

_LOGGER.debug(f"setup_platform: {config}")
hub = hass.data[DOMAIN]
if not hub._online:
Expand Down Expand Up @@ -149,3 +149,4 @@ def stop_cover(self, **kwargs):
self.is_opening = False
self.is_closing = False
self.schedule_update_ha_state(False)

15 changes: 0 additions & 15 deletions custom_components/gpiod/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def verify_gpiochip(self, path):
_LOGGER.debug(f"verify_gpiochip gpiodevice: {path} has pinctrl")
return True


async def startup(self, _):
"""Stuff to do after starting."""
_LOGGER.debug(f"startup {DOMAIN} hub")
Expand All @@ -100,17 +99,12 @@ async def startup(self, _):
# setup lines
self.update_lines()

# read initial states for sensors
# for port in self._config:
# self._entities[port].update()

if not self._edge_events:
return

_LOGGER.debug("Start listener")
self._hass.loop.add_reader(self._lines.fd, self.handle_events)


def cleanup(self, _):
"""Stuff to do before stopping."""
_LOGGER.debug(f"cleanup {DOMAIN} hub")
Expand Down Expand Up @@ -149,11 +143,6 @@ def handle_events(self):

def add_switch(self, entity, port, active_low, bias, drive_mode) -> None:
_LOGGER.debug(f"in add_switch {port}")
# read current status of the lines
# line = self._chip.request_lines({ port: {} })
# value = True if line.get_value(port) == Value.ACTIVE else False
# line.release()
# _LOGGER.debug(f"current value for port {port}: {value}, output_value: {value ^ active_low}")

self._entities[port] = entity
self._config[port] = gpiod.LineSettings(
Expand All @@ -162,10 +151,7 @@ def add_switch(self, entity, port, active_low, bias, drive_mode) -> None:
drive = DRIVE[drive_mode],
active_low = active_low,
output_value = Value.ACTIVE if entity.is_on else Value.INACTIVE
# output_value = Value.ACTIVE if value ^ active_low else Value.INACTIVE,
# output_value = Value.INACTIVE
)
# self.update_lines()

def turn_on(self, port) -> None:
_LOGGER.debug(f"in turn_on")
Expand Down Expand Up @@ -195,7 +181,6 @@ def add_sensor(self, entity, port, active_low, bias, debounce) -> None:
output_value = Value.ACTIVE if entity.is_on else Value.INACTIVE,
)
self._edge_events = True
# self.update_lines()

def update(self, port, **kwargs):
return self._lines.get_value(port) == Value.ACTIVE
Expand Down
51 changes: 11 additions & 40 deletions custom_components/gpiod/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
})
)


async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
Expand All @@ -56,31 +55,18 @@ async def async_setup_platform(

switches = []
for switch in config.get(CONF_SWITCHES):
# if switch[CONF_PERSISTENT]:
# switches.append(
# PersistentRPiGPIOSwitch(
# hub,
# switch[CONF_NAME],
# switch[CONF_PORT],
# switch.get(CONF_UNIQUE_ID) or f"{DOMAIN}_{switch[CONF_PORT]}_{switch[CONF_NAME].lower().replace(' ', '_')}",
# switch.get(CONF_ACTIVE_LOW) or switch.get("invert_logic") or DEFAULT_ACTIVE_LOW,
# switch.get(CONF_BIAS),
# switch.get(CONF_DRIVE)
# )
# )
# else:
switches.append(
GPIODSwitch(
hub,
switch[CONF_NAME],
switch[CONF_PORT],
switch.get(CONF_UNIQUE_ID) or f"{DOMAIN}_{switch[CONF_PORT]}_{switch[CONF_NAME].lower().replace(' ', '_')}",
switch.get(CONF_ACTIVE_LOW) or switch.get("invert_logic") or DEFAULT_ACTIVE_LOW,
switch.get(CONF_BIAS),
switch.get(CONF_DRIVE),
switch[CONF_PERSISTENT]
)
switches.append(
GPIODSwitch(
hub,
switch[CONF_NAME],
switch[CONF_PORT],
switch.get(CONF_UNIQUE_ID) or f"{DOMAIN}_{switch[CONF_PORT]}_{switch[CONF_NAME].lower().replace(' ', '_')}",
switch.get(CONF_ACTIVE_LOW) or switch.get("invert_logic") or DEFAULT_ACTIVE_LOW,
switch.get(CONF_BIAS),
switch.get(CONF_DRIVE),
switch[CONF_PERSISTENT]
)
)

async_add_entities(switches)

Expand All @@ -91,7 +77,6 @@ class GPIODSwitch(SwitchEntity, RestoreEntity):
def __init__(self, hub, name, port, unique_id, active_low, bias, drive, persistent):
_LOGGER.debug(f"GPIODSwitch init: {port} - {name} - {unique_id} - active_low: {active_low} - bias: {bias} - drive: {drive}")
self._hub = hub
# self._attr_name = name
self.name = name
self.unique_id = unique_id
self._port = port
Expand Down Expand Up @@ -127,17 +112,3 @@ def update(self):
self.is_on = self._hub.update(self._port)
self.schedule_update_ha_state(False)


# class PersistentRPiGPIOSwitch(GPIODSwitch, RestoreEntity):
# async def async_added_to_hass(self) -> None:
# """Call when the switch is added to hass."""
# await super().async_added_to_hass()
# state = await self.async_get_last_state()
# _LOGGER.debug(f"recovering state: {state}")
# if not state:
# return
# self.is_on = True if state.state == STATE_ON else False
# if self.is_on:
# await self.async_turn_on()
# else:
# await self.async_turn_off()

0 comments on commit 5dee0e7

Please sign in to comment.