1
0
Fork
You've already forked divera_python
0

api/v2/models-async #1

Closed
fabbecker wants to merge 0 commits from api/v2/models-async into api/v2/models
pull from: api/v2/models-async
merge into: fabbecker:api/v2/models
fabbecker:main
fabbecker:v0.8.0rc1
fabbecker:docker-compatibility
fabbecker:v0.0.7
fabbecker:pages
fabbecker:File
fabbecker:Model
fabbecker:client
fabbecker:MessageChannel
fabbecker:Event
fabbecker:Alarm
fabbecker:config
fabbecker:News
fabbecker:v0.0.6
fabbecker:pull-model
fabbecker:websocket
fabbecker:sans-io
fabbecker:api/v1
fabbecker:api/v2/auth
fabbecker:docs
fabbecker:v0.0.5
fabbecker:v0.0.4
fabbecker:polling-callback
fabbecker:v0.0.3
fabbecker:utils
fabbecker:api/v2/events
fabbecker:api/v2/alarm
fabbecker:api/v2/pull
fabbecker:v0.0.1
fabbecker:devel
fabbecker:AlarmAndEvent
fabbecker:credentialstorage
fabbecker:api/v2/models
fabbecker:decorated-authentication
fabbecker:serialization
fabbecker:api/v2/news
fabbecker:api/v2/alarms/confirm

Use async functionality on abstract api.v2.models.ModelAPI

Use async functionality on abstract api.v2.models.ModelAPI
This reverts commit e6804e65f5.
Arguments:
* username: email address of the user
* password: password of the user
* domain: domain of the server (needed if not set in config yet)
This part has been generated by manually copying the json response from the api documentation from:
https://api.divera247.com/?urls.primaryName=api%2Fv2%2Falarm#/CRUD/get_api_v2_alarms__id_
https://api.divera247.com/?urls.primaryName=api%2Fv2%2Fnews#/CRUD/get_api_v2_news__id_
https://api.divera247.com/?urls.primaryName=api%2Fv2%2Fevent#/CRUD/get_api_v2_events
saving each of them to a json file, reading the data with a python script and comparing them with the following code
all = list(set(alarm.keys()).intersection(event.keys()).intersection(news.keys()))
print("\n\n".join([f" @property\n def {x}(self) -> str:\n return self.data['{x}']" for x in all]) + "\n")
The type descriptors have been manually replaced
* remove type_ argument
* replace id_ with object_id
* use response_text instead of note
Make a dictionary of all models as in bfad9c34ad
```
alarm = {'id': 123, 'foreign_id': '2019-1023', 'author_id': 123456789, 'alarmcode_id': 123456789, 'date': 0, 'priority': True, 'title': 'FEUER3', 'text': 'Unklare Rauchentwicklung im Hafen', 'address': 'Hauptstraße 247, 12345 Musterstadt', 'lat': 0, 'lng': 0, 'scene_object': 'string', 'caller': 'string', 'patient': 'string', 'remark': 'string', 'units': 'string', 'destination': True, 'destination_address': 'string', 'destination_lat': 0, 'destination_lng': 0, 'additional_text_1': 'string', 'additional_text_2': 'string', 'additional_text_3': 'string', 'report': '2 Einsatztabschnitte gebildet, 3 C-Rohre im Einsatz', 'cluster': [0], 'group': [0], 'user_cluster_relation': [0], 'vehicle': ['string'], 'private_mode': True, 'notification_type': 0, 'notification_filter_vehicle': True, 'notification_filter_status': True, 'notification_filter_access': True, 'notification_filter_status_ids': [0], 'send_push': True, 'send_sms': True, 'send_call': True, 'send_mail': True, 'send_pager': True, 'response_time': 0, 'closed': True, 'new': True, 'editable': True, 'answerable': True, 'hidden': True, 'deleted': True, 'ucr_adressed': [0], 'ucr_answered': [0], 'ucr_self_addressed': True, 'ucr_self_status_id': 0, 'ucr_self_note': 'string', 'count_recipients': 0, 'count_read': 0, 'ts_response': 0, 'ts_publish': 0, 'ts_close': 0, 'ts_create': 0, 'ts_update': 0, 'notification_filter_status_access': True}
event = {'id': 123, 'foreign_id': 12345678, 'author_id': 123456789, 'date': 0, 'title': 'Weihnachtsfeier', 'text': 'Gemütlicher Jahresausklang, eingeladen sind auch euren Partner', 'address': 'Ristorante Alfredo', 'cluster': [0], 'group': [0], 'user_cluster_relation': [0], 'private_mode': True, 'notification_type': 0, 'send_push': True, 'send_sms': True, 'send_call': True, 'send_mail': True, 'send_pager': True, 'send_reminder': True, 'reminder': {'ts': 0, 'send_push': True, 'send_mail': True, 'executed': True}, 'new': True, 'editable': True, 'answerable': True, 'hidden': True, 'deleted': True, 'show_result_count': 0, 'show_result_names': 0, 'multiple_answers': True, 'custom_answers': True, 'response_type': 0, 'response_until': True, 'ts_response': 0, 'access_count': True, 'access_names': True, 'participation': True, 'note': 'bin dabei!', 'ucr_adressed': [0], 'ucr_answered': [0], 'ucr_self_addressed': True, 'count_recipients': 0, 'count_read': 0, 'ts_create': 0, 'ts_update': 0}
news = {'id': 123, 'foreign_id': '2019-1023', 'author_id': 123456789, 'date': 0, 'title': 'Neue Dienstanweisung', 'text': 'Rückwärtsfahren nur mit Einweiser', 'address': 'Raum 1.23', 'cluster': [0], 'group': [0], 'user_cluster_relation': [0], 'private_mode': True, 'notification_type': 0, 'send_push': True, 'send_sms': True, 'send_call': True, 'send_mail': True, 'send_pager': True, 'survey': True, 'surveys': [{'id': 0, 'title': 'Mit wie vielen Personen nehmt ihr am Sommerfest teil?', 'show_result_count': 0, 'show_result_names': 0, 'access_count': True, 'access_names': True, 'multiple_answers': True, 'custom_answers': True, 'response_until': True, 'ts_response': 0, 'answers': {}, 'answerSorting': ['string', 0]}], 'new': True, 'editable': True, 'answerable': True, 'hidden': True, 'deleted': True, 'ucr_adressed': [0], 'ucr_answered': [0], 'ucr_self_addressed': True, 'count_recipients': 0, 'count_read': 0, 'ts_publish': 0, 'archive': True, 'ts_archive': 0, 'ts_create': 0, 'ts_update': 0}
```
Make a list of all common attributes
```
common = list(set(alarm.keys()).intersection(event.keys()).intersection(news.keys()))
```
print all special attributes
```
def attribute_to_text(attr, ex):
 return "\n".join([
 f" @property",
 f" def {attr}(self) -> {type(ex).__name__}:",
 f" return self.data['{attr}']",
 ])
for a in alarm.keys():
 if a not in common:
 print(attribute_to_text(a, alarm[a]) + "\n")
```
Copy the output into the file
Manually change lat and lng type descriptors to float
initiate self.client = divera.Client()
log in if required
Change resulted in circular imports
This reverts commit b2bf262423.
Give b2bf262423 another go
Allow creating Events with custom attributes by calling Event.__init__
Conform to 96b0d54699 
Use Events to test the changes made on this branch
CrudAPI is used as parent class for API wrappers to provide the basic methods for every model
fabbecker closed this pull request 2023年08月04日 13:41:19 +02:00

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.
No reviewers
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
fabbecker/divera_python!1
Reference in a new issue
fabbecker/divera_python
No description provided.
Delete branch "api/v2/models-async"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?