Skip to content

Commit

Permalink
feat: read pin type a switch setup
Browse files Browse the repository at this point in the history
  • Loading branch information
pilotak committed Jan 16, 2024
1 parent dec1db6 commit c44d709
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion custom_components/mcp2221/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"integration_type": "hub",
"iot_class": "local_polling",
"issue_tracker": "https://github.com/pilotak/homeassistant-mcp2221/issues",
"requirements": ["mcp2221~=1.0"],
"requirements": ["mcp2221~=1.1"],
"version": "1.0.0",
"usb": [
{
Expand Down
8 changes: 6 additions & 2 deletions custom_components/mcp2221/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ def __init__(
self._pin = pin

# init GP
prev_state = self._device.ReadGP(self._pin)
self._state = bool(prev_state)
prev_state = False

if self._device.GetGPType(self._pin) == MCP2221.TYPE.OUTPUT:
prev_state = bool(self._device.ReadGP(self._pin))
self._state = prev_state

self._device.InitGP(pin, MCP2221.TYPE.OUTPUT, prev_state)

async def async_added_to_hass(self) -> None:
Expand Down

0 comments on commit c44d709

Please sign in to comment.