Commit 67170649 authored by vertighel's avatar vertighel
Browse files

Fase 1 devices (parziale): BaseDevice su netio/siemens/domotics,...


Fase 1 devices (parziale): BaseDevice su netio/siemens/domotics, state/status/connection su astelco/mercury, lock su stx.py, fix ipcam.py, ultimo commento italiano

- netio.py, siemens.py, domotics.py: ereditano BaseDevice via
  super().__init__(url), invece di reimplementare url/error a mano.
- domotics.py: rimosso il `return` morto in cima a get()/put() che
  rendeva quei metodi completamente non funzionanti (bug da audit).
- astelco.py: `state` da int bit-coded a bool (True = errore presente),
  sola lettura — è un registro hardware, non c'è nulla da settare.
  `status` resta invariato (già verboso). init.html aggiornato con
  "map": "bool_yesno" e rimosso "unit": "#" ormai non pertinente.
- mercury.py: `status` (bool, reachability) rinominato in `connection`
  per coerenza con lo stesso concetto in atik.py; libera "status" dal
  significato ambiguo. Nessun consumer API da aggiornare oggi
  (/stage/status chiama in realtà is_init). Promemoria aggiunto a
  PLAN.md per applicare la stessa convenzione nella fase API.
- stx.py: threading.Lock() a guardia di _wait_if_needed()/
  _last_command_time, letto e scritto sia dal thread di loop che dai
  thread di richiesta senza sincronizzazione — poteva far sforare il
  rate-limit di 50ms tra comandi.
- ipcam.py: DlinkDCSCamera.__init__ ora chiama super().__init__(url)
  invece di duplicarne il corpo; save_image da @property (con un
  parametro filename impossibile da passare, e un side-effect di
  scrittura su disco al semplice accesso) a metodo normale.
- atik.py: tradotto/rimosso l'ultimo commento italiano rimasto in
  devices/.

Co-Authored-By: default avatarClaude Sonnet 5 <noreply@anthropic.com>
parent 0658217f
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -196,6 +196,18 @@ binned frames). None of the below are closed.

### 3. API

- [ ] Apply the devices-phase `state`/`status`/`connection` naming
      convention at this layer too (decided while resolving
      astelco.py/mercury.py): `state` = bool, actionable/settable where
      it makes sense; `status` = read-only, verbose/descriptive;
      `connection` = read-only bool reachability check (matches
      `atik.py`'s existing `connection` property). Does not apply to the
      camera_state int enum (0=Idle...6=Flushing, shared across all 6
      cameras) — that's a separate, already-consistent convention, don't
      touch it. `mercury.py`'s `status``connection` rename (devices
      phase) currently has no API consumer (`/stage/status` actually
      calls `is_init`, not `.status`) — nothing to update today, but
      keep the convention in mind for any new stage/mercury route.
- [ ] Delete `environment.py`, `common.py`, `test.py` (dead, see
      above), the duplicate `telescope.py:268-327` classes, and the
      `.#webcam.py` lock file.
+10 −4
Original line number Diff line number Diff line
@@ -323,16 +323,22 @@ class Telescope(OpenTSI):
    @property
    def state(self):
        """
        int or None: The global operational status of the telescope.
        bool or None: True if the telescope reports a fault, False if
        operational.

        Returns a bit-coded integer from TELESCOPE.STATUS.GLOBAL.
        0 means operational.
        Derived from the bit-coded TELESCOPE.STATUS.GLOBAL (0 =
        operational, anything else = some fault bit set) — see ``status``
        for the detailed diagnostic string. Read-only: this mirrors a
        hardware fault register, there's nothing to set.
        """

        res = self.get("TELESCOPE.STATUS.GLOBAL")
        if self.error:
            return None
        return res
        try:
            return int(res) != 0
        except (TypeError, ValueError):
            return None

    def clear_error(self, n):
        """
+0 −1
Original line number Diff line number Diff line
@@ -107,7 +107,6 @@ class Camera(BaseDevice):
                    msg = "Atik connected but failed to acquire handle"
                    if msg not in self.error: self.error.append(msg)
            else:
                # FIX: Aggiungiamo l'errore qui se la camera non c'è
                msg = "No Atik devices detected on USB"
                if msg not in self.error: 
                    self.error.append(msg)
+3 −5
Original line number Diff line number Diff line
@@ -10,20 +10,19 @@ import requests
# Other templates
from ..utils import check
from ..utils.logger import log
from .basedevice import BaseDevice


class Sonoff:
class Sonoff(BaseDevice):
    def __init__(self, url, id):
        self.url = url
        super().__init__(url)
        self.addr = self.url + "/json.htm"
        self.timeout = 3
        self.error = None
        self.id = id
        requests.packages.urllib3.disable_warnings()  # For verify=False

    @check.request_errors
    def get(self, param=None, id=None):
        return
        base_params = {"type": "devices"}
        if id:
            base_params.update({"rid": id})
@@ -56,7 +55,6 @@ class Sonoff:

    @check.request_errors
    def put(self, params={}, id=None):
        return
        base_params = {"type": "command", "idx": id}
        params.update(base_params)
        res = requests.get(self.addr,
+2 −4
Original line number Diff line number Diff line
@@ -20,10 +20,9 @@ class DlinkDCSCamera(BaseDevice):
    def __init__(self, url):
        '''Constructor.'''

        self.url = url
        super().__init__(url)
        self.addr = self.url
        self.timeout = 3
        self.error = []

    def get_stream(self, method):
        """
@@ -170,7 +169,6 @@ class Webcam(DlinkDCSCamera):


    
    @property
    def save_image(self, filename="temp.jpeg"):
        '''Save a IP Camera image snapshot.'''

Loading