Skip to content

Commit

Permalink
[FIX] write tags
Browse files Browse the repository at this point in the history
  • Loading branch information
archetipo committed Nov 27, 2024
1 parent 1de021b commit 0196cd7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ class CaAnagRegistroAccesso(models.Model):
)
work_id_number = fields.Char(string='ID Number')
state = fields.Selection([
('no_sync', 'No Sync'),
('to_sync', 'To Sync'),
('sent', 'Sent'),
('sync_done', 'Sync Done'),
('sync_error', 'Sync Error'),
], string="Sync State", readonly=True)
], string="Sync State", readonly=True, default='no_sync')

def aggiungi_riga_accesso(
self, ca_punto_accesso_id,
Expand Down
18 changes: 9 additions & 9 deletions inrim_controllo_accessi_rfidglobal/models/Max5010_rfid_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def make_EventsResponse_from_dict(cls, data: dict, tz) -> EventsResponse:
events.eventRecords[idx] = EventRecord(**events.eventRecords[idx])
return events

def post_request(self, path: str, body: dict) -> dict:
def post_request(self, path: str, body: dict) -> (dict, str):
payload = {"device": self.device_ip}
payload.update(body)
self.connction_error = False
Expand All @@ -166,16 +166,16 @@ def post_request(self, path: str, body: dict) -> dict:
with httpx.Client(timeout=self.timeout) as client:
response = client.post(path, json=payload, headers=self.headers)
if response.status_code == 200:
return response.json()
return response.json(), "OK"
else:
self.response_error = True
logger.info(
f"{path}, Status Code: {response.status_code}, payload: {payload}")
return {}
msg = f"Error {path}, Status Code: {response.status_code}, payload: {payload}"
logger.info(msg)
return {}, msg
except Exception as e:
logger.error(f"{path}, Error: {e}", exc_info=True)
msg = f"Exception {path}, Error: {e}"
self.connction_error = True
return {}
return {}, msg

def load_info(self) -> Device:
self.online = False
Expand Down Expand Up @@ -226,8 +226,8 @@ def write_tags(self, tags_body: dict) -> dict:
ar['message'] = msg
return ar
rest_path = f"{self.base_url}/add-tags"
res = self.post_request(rest_path, tags_body)
res['message'] = "OK"
res, msg = self.post_request(rest_path, tags_body)
res['message'] = msg
return res

def update_clock(self) -> ActionResponse:
Expand Down

0 comments on commit 0196cd7

Please sign in to comment.