11![ licence] ( https://img.shields.io/badge/license-MIT-green )
22![ issues] ( https://img.shields.io/github/issues/matejgordon/unipyaccess )
3- [ ![ deploy] ( https://img.shields.io/github/actions/workflow/status/matejgordon/unipyaccess/deploy.yml )] ( https://github.com/matejgordon/unipyaccess/actions/workflows/deploy.yml )
3+ [ ![ deploy] ( https://img.shields.io/github/actions/workflow/status/matejgordon/unipyaccess/deploy.yml )] ( https://github.com/matejgordon/unipyaccess/actions/workflows/deploy.yml )
44![ tag] ( https://img.shields.io/github/v/tag/matejgordon/unipyaccess )
55
66# unipyaccess
77
8- ` unipyaccess ` is a Python package designed to interface with the ** Unifi Access** system. This package provides a simple and efficient way to manage users in Unifi Access, including authentication, retrieval, creation, activation, deactivation, deletion, and updating of user groups.
8+ ` unipyaccess ` is a Python package designed to interface with the ** Unifi Access** system. This package provides a simple and efficient way to manage users in Unifi Access, including authentication, retrieval, creation, activation, deactivation, deletion, and updating of user groups and hardware settings .
99
1010> [ !NOTE]
1111> This implementation uses Unifi API endpoints with admin user authentication. It does ** not** utilize the latest, in my opinion half-baked Unifi API.
1818- Authenticate with Unifi Access using admin credentials.
1919- Retrieve, create, activate, deactivate, and delete user accounts.
2020- Update user group assignments.
21+ - Manage Unifi Access hardware, including access methods, display brightness, and device status.
2122
2223## Installation
2324
@@ -61,94 +62,207 @@ import os
6162load_dotenv()
6263
6364# Initialize the UnipyAccess API client
64- unifiApi = UnipyAccess(
65+ unipy = UnipyAccess(
6566 base_url = os.getenv(' UNIFI_CONTROLLER_ADDRESS' ),
6667 username = os.getenv(' UNIFI_LOGIN' ),
6768 password = os.getenv(' UNIFI_PASSWORD' ),
6869 verify = os.getenv(' VERIFY_SSL' )
6970)
7071
71- # Example: Create a new user
72- users = [
73- {
74- " first_name" : " John" ,
75- " last_name" : " Doe" ,
76- " PersonId" : 124 ,
77- " group_ids" : [" bc1bf76d-5d2a-4a90-ae50-6aca02bccc63" ]
78- }
79- ]
80- unifiApi.create_unifi_users(users)
72+ # Features
73+ users = unipy.users.get_users()
74+
75+ new_user = {
76+ " first_name" : " Python" ,
77+ " last_name" : " Test" ,
78+ " PersonId" : 98765 ,
79+ }
80+
81+ unipy.users.create_user(new_user)
82+ unipy.users.deactivate_user(uuid)
83+ unipy.users.activate_user(uuid)
84+ unipy.users.set_user_group(uuid, group_uuid)
85+ unipy.users.delete_user(uuid)
86+
87+ # Hardware management
88+ devices = unipy.hardware.get_devices()
89+
90+ unipy.hardware.get_device(device_id)
91+ unipy.hardware.set_access_method(device_id, [" pin" , " nfc" , " mobile_tap" , " mobile_button" ])
92+ unipy.hardware.set_doorbell_trigger(device_id, " tap" )
93+ unipy.hardware.set_status_light(device_id, " on" )
94+ unipy.hardware.set_display_brightness(device_id, 50 )
95+ unipy.hardware.set_status_sound(" f4e2c6d3085d" , 30 ) # For models other than UA G2 Pro use "on" or "off"
96+ unipy.hardware.get_device_capabilities(device_id)
97+ unipy.hardware.get_device_model(device_id)
98+ unipy.hardware.restart_device(device_id)
8199```
82100
83101## Methods
84102
85- ### 1. ` get_unifi_users() `
86- Fetches the list of users from Unifi Access.
103+ ### User Management
104+
105+ #### 1. ` unipy.users.create_user(new_user) `
106+ Creates a new user.
107+
108+ ** Parameters:**
109+ - ` new_user ` (dict): Dictionary containing user details:
110+ - ` first_name ` (str): User's first name.
111+ - ` last_name ` (str): User's last name.
112+ - ` PersonId ` (str): Optional employee number.
113+ - ` group_ids ` (list): Optional list of group IDs.
87114
88115** Usage:**
89116
90117``` python
91- users = unifiApi.get_unifi_users()
92- print (users)
118+ new_user = {
119+ " first_name" : " Jane" ,
120+ " last_name" : " Doe" ,
121+ " PersonId" : " 789" ,
122+ " group_ids" : [" group-123" ]
123+ }
124+ unipy.users.create_user(new_user)
93125```
94126
95- ### 2. ` create_unifi_users( users)`
96- Creates new users .
127+ #### 2. ` unipy. users.deactivate_user(uuid )`
128+ Deactivates a user .
97129
98130** Parameters:**
99- - ` users ` (list): List of user dictionaries containing:
100- - ` first_name ` (str): User's first name.
101- - ` last_name ` (str): User's last name.
102- - ` PersonId ` (str): Optional employee number.
103- - ` group_ids ` (list): Optional list of group IDs.
131+ - ` uuid ` (str): User’s unique identifier.
132+
133+ ** Usage:**
134+
135+ ``` python
136+ unipy.users.deactivate_user(" user-123" )
137+ ```
138+
139+ #### 3. ` unipy.users.activate_user(uuid) `
140+ Activates a user.
141+
142+ ** Parameters:**
143+ - ` uuid ` (str): User’s unique identifier.
144+
145+ ** Usage:**
146+
147+ ``` python
148+ unipy.users.activate_user(" user-123" )
149+ ```
150+
151+ #### 4. ` unipy.users.set_user_group(uuid, group_uuid) `
152+ Updates the user group assignment.
153+
154+ ** Parameters:**
155+ - ` uuid ` (str): User’s unique identifier.
156+ - ` group_uuid ` (str): Group’s unique identifier.
157+
158+ ** Usage:**
159+
160+ ``` python
161+ unipy.users.set_user_group(" user-123" , " group-789" )
162+ ```
163+
164+ #### 5. ` unipy.users.delete_user(uuid) `
165+ Deletes a user.
166+
167+ ** Parameters:**
168+ - ` uuid ` (str): User’s unique identifier.
169+
170+ ** Usage:**
171+
172+ ``` python
173+ unipy.users.delete_user(" user-123" )
174+ ```
175+
176+ ### Hardware Management
177+
178+ #### 1. ` unipy.hardware.get_devices() `
179+ Fetches a list of hardware devices.
180+
181+ ** Usage:**
182+
183+ ``` python
184+ devices = unipy.hardware.get_devices()
185+ ```
186+
187+ #### 2. ` unipy.hardware.get_device(device_id) `
188+ Fetches details of a specific device.
189+
190+ ** Usage:**
191+
192+ ``` python
193+ device = unipy.hardware.get_device(" device-123" )
194+ ```
195+
196+ #### 3. ` unipy.hardware.set_access_method(device_id, enabled_methods) `
197+ Sets the access methods for a device.
198+
199+ ** Usage:**
200+
201+ ``` python
202+ unipy.hardware.set_access_method(" device-123" , [" pin" , " nfc" ])
203+ ```
204+
205+ #### 4. ` unipy.hardware.set_doorbell_trigger(device_id, doorbell_trigger) `
206+ Sets the doorbell trigger type for a device.
207+
208+ ** Usage:**
209+
210+ ``` python
211+ unipy.hardware.set_doorbell_trigger(" device-123" , " tap" )
212+ ```
213+
214+ #### 5. ` unipy.hardware.set_status_light(device_id, status_light) `
215+ Sets the status light for a device.
104216
105217** Usage:**
106218
107219``` python
108- users = [
109- {" first_name" : " Jane" , " last_name" : " Doe" , " PersonId" : " 789" , " group_ids" : [" group-123" ]}
110- ]
111- unifiApi.create_unifi_users(users)
220+ unipy.hardware.set_status_light(" device-123" , " on" )
112221```
113222
114- ### 3 . ` deactivate_unifi_users(users )`
115- Deactivates users .
223+ #### 6 . ` unipy.hardware.set_display_brightness(device_id, brightness )`
224+ Sets the display brightness for a device .
116225
117226** Usage:**
118227
119228``` python
120- users = [{" id" : " user-123" }]
121- unifiApi.deactivate_unifi_users(users)
229+ unipy.hardware.set_display_brightness(" device-123" , 50 )
122230```
123231
124- ### 4 . ` activate_unifi_users(users )`
125- Activates users .
232+ #### 7 . ` unipy.hardware.set_status_sound(device_id, status_sound )`
233+ Sets the status sound for a device .
126234
127235** Usage:**
128236
129237``` python
130- users = [{" id" : " user-123" }]
131- unifiApi.activate_unifi_users(users)
238+ unipy.hardware.set_status_sound(" device-123" , 30 )
132239```
133240
134- ### 5 . ` delete_unifi_users(users )`
135- Deletes users .
241+ #### 8 . ` unipy.hardware.get_device_capabilities(device_id )`
242+ Fetches the capabilities of a device .
136243
137244** Usage:**
138245
139246``` python
140- users = [{" id" : " user-123" }]
141- unifiApi.delete_unifi_users(users)
247+ capabilities = unipy.hardware.get_device_capabilities(" device-123" )
142248```
143249
144- ### 6 . ` set_users_group(users )`
145- Updates user group assignments .
250+ #### 9 . ` unipy.hardware.get_device_model(device_id )`
251+ Fetches the model of a device .
146252
147253** Usage:**
148254
149255``` python
150- users = [{" id" : " user-123" , " group" : " group-456" }]
151- unifiApi.set_users_group(users)
256+ model = unipy.hardware.get_device_model(" device-123" )
257+ ```
258+
259+ #### 10. ` unipy.hardware.restart_device(device_id) `
260+ Restarts a device.
261+
262+ ** Usage:**
263+
264+ ``` python
265+ unipy.hardware.restart_device(" device-123" )
152266```
153267
154268## Example Code
@@ -160,31 +274,46 @@ import os
160274
161275load_dotenv()
162276
163- unifiApi = UnipyAccess(
277+ unipy = UnipyAccess(
164278 base_url = os.getenv(' UNIFI_CONTROLLER_ADDRESS' ),
165279 username = os.getenv(' UNIFI_LOGIN' ),
166280 password = os.getenv(' UNIFI_PASSWORD' ),
167281 verify = os.getenv(' VERIFY_SSL' )
168282)
169283
170284# Retrieve users
171- print (unifiApi.get_unifi_users())
285+ users = unipy.users.get_users()
286+ print (users)
172287
173288# Create a user
174- new_user = [{" first_name" : " Alice" , " last_name" : " Smith" , " PersonId" : " 125" }]
175- unifiApi.create_unifi_users(new_user)
289+ new_user = {
290+ " first_name" : " Alice" ,
291+ " last_name" : " Smith" ,
292+ " PersonId" : " 125"
293+ }
294+ unipy.users.create_user(new_user)
176295
177296# Activate a user
178- unifiApi.activate_unifi_users([{ " id " : " user-123" }] )
297+ unipy.users.activate_user( " user-123" )
179298
180299# Deactivate a user
181- unifiApi.deactivate_unifi_users([{ " id " : " user-123" }] )
300+ unipy.users.deactivate_user( " user-123" )
182301
183302# Delete a user
184- unifiApi.delete_unifi_users([{ " id " : " user-123" }] )
303+ unipy.users.delete_user( " user-123" )
185304
186305# Update user group
187- unifiApi.set_users_group([{" id" : " user-123" , " group" : " group-789" }])
306+ unipy.users.set_user_group(" user-123" , " group-789" )
307+
308+ # Hardware Management
309+ # Get devices
310+ devices = unipy.hardware.get_devices()
311+ print (devices)
312+
313+ # Set device configurations
314+ unipy.hardware.set_access_method(" device-123" , [" pin" , " nfc" ])
315+ unipy.hardware.set_display_brightness(" device-123" , 50 )
316+ unipy.hardware.set_status_sound(" device-123" , " on" )
188317```
189318
190319## License
0 commit comments