@@ -89,12 +89,24 @@ def verify_gpiochip(self, path):
89
89
_LOGGER .debug (f"verify_gpiochip gpiodevice: { path } has pinctrl" )
90
90
return True
91
91
92
+ def verify_port_ready (self , port : int ):
93
+ info = self ._chip .get_line_info (port )
94
+ _LOGGER .debug (f"original port info: { info } " )
95
+ if info .used and info .consumer != DOMAIN :
96
+ _LOGGER .error (f"Port { port } already in use by { info .consumer } " )
97
+ raise HomeAssistantError (f"Port { port } already in use by { info .consumer } " )
98
+
99
+
92
100
async def startup (self , _ ):
93
101
"""Stuff to do after starting."""
94
102
_LOGGER .debug (f"startup { DOMAIN } hub" )
95
103
if not self ._online :
104
+ _LOGGER .debug (f"integration is not online" )
96
105
return
97
-
106
+ if not self ._config :
107
+ _LOGGER .debug (f"gpiod config is empty" )
108
+ return
109
+
98
110
# setup lines
99
111
try :
100
112
self .update_lines ()
@@ -125,16 +137,12 @@ def hub_id(self) -> str:
125
137
return self ._id
126
138
127
139
def update_lines (self ) -> None :
128
- if not self ._online :
129
- _LOGGER .debug (f"gpiod hub not online { self ._path } " )
130
- if not self ._config :
131
- _LOGGER .debug (f"gpiod config is empty" )
132
140
if self ._lines :
133
141
self ._lines .release ()
134
142
135
143
_LOGGER .debug (f"updating lines: { self ._config } " )
136
144
self ._lines = self ._chip .request_lines (
137
- consumer = "rpi_gpio" ,
145
+ consumer = DOMAIN ,
138
146
config = self ._config
139
147
)
140
148
_LOGGER .debug (f"update_lines new lines: { self ._lines } " )
@@ -146,9 +154,8 @@ def handle_events(self):
146
154
147
155
def add_switch (self , entity , port , active_low , bias , drive_mode , init_output_value = True ) -> None :
148
156
_LOGGER .debug (f"in add_switch { port } " )
149
-
150
- info = self ._chip .get_line_info (port )
151
- _LOGGER .debug (f"original line info: { info } " )
157
+ self .verify_online ()
158
+ self .verify_port_ready (port )
152
159
153
160
self ._entities [port ] = entity
154
161
self ._config [port ] = gpiod .LineSettings (
@@ -171,9 +178,8 @@ def turn_off(self, port) -> None:
171
178
172
179
def add_sensor (self , entity , port , active_low , bias , debounce ) -> None :
173
180
_LOGGER .debug (f"in add_sensor { port } " )
174
-
175
- info = self ._chip .get_line_info (port )
176
- _LOGGER .debug (f"original line info: { info } " )
181
+ self .verify_online ()
182
+ self .verify_port_ready (port )
177
183
178
184
# read current status of the sensor
179
185
line = self ._chip .request_lines ({ port : {} })
0 commit comments