Skip to content

Commit

Permalink
fix imports, fix some and suppress remaining errors in Schedule.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gnmerritt committed Sep 12, 2022
1 parent bb03dfe commit 286b4ff
Showing 1 changed file with 25 additions and 33 deletions.
58 changes: 25 additions & 33 deletions BAC0/core/functions/Schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,24 @@
# Copyright (C) 2015 by Christian Tremblay, P.Eng <[email protected]>
# Licensed under LGPLv3, see file LICENSE in this source tree.
#
"""
ScheduleWrite.py - creation of ReinitializeDeviceRequest
"""
from ..io.Read import find_reason
from ..io.IOExceptions import (
SegmentationNotSupported,
ReadPropertyException,
ReadPropertyMultipleException,
NoResponseFromController,
ApplicationNotStarted,
)
from ..io.IOExceptions import NoResponseFromController
from ...core.utils.notes import note_and_log

# --- standard Python modules ---
import datetime as dt
from datetime import time as dt_time
import typing as t

# --- 3rd party modules ---
from bacpypes.pdu import Address, GlobalBroadcast
from bacpypes.primitivedata import Integer, Date, Time, CharacterString
from bacpypes.basetypes import DateTime
from bacpypes.pdu import Address
from bacpypes.primitivedata import Integer
from bacpypes.apdu import WritePropertyRequest, SimpleAckPDU
from bacpypes.iocb import IOCB
from bacpypes.core import deferred
from bacpypes.basetypes import DateTime, DailySchedule, TimeValue, Time
from bacpypes.basetypes import DailySchedule, TimeValue
from bacpypes.constructeddata import ArrayOf, Any

from bacpypes.primitivedata import Null, Atomic, Integer, Unsigned, Real, Enumerated

from datetime import time as dt_time
from datetime import datetime as dt
from bacpypes.primitivedata import Real, Enumerated


@note_and_log
Expand Down Expand Up @@ -147,7 +134,7 @@ def send_weeklyschedule_request(self, request, timeout=10):
if not isinstance(apdu, SimpleAckPDU): # expect an ACK
self._log.warning("Not an ack, see debug for more infos.")
self._log.debug(
"Not an ack. | APDU : {} / {}".format((apdu, type(apdu)))
"Not an ack. | APDU : {} / {}".format(apdu, type(apdu))
)
return
if iocb.ioError: # unsuccessful: error/reject/abort
Expand Down Expand Up @@ -205,8 +192,8 @@ def _read(prop):
except Exception:
raise ()

schedule = {}
_state_text = None
schedule: t.Dict[str, t.Union[t.Dict, t.List]] = {}
_state_text: t.Union[str, range, t.List[str], None] = None
offset_MV = 0 if len(object_references) == 0 else 1

try:
Expand Down Expand Up @@ -239,29 +226,34 @@ def _read(prop):
schedule["object_references"] = []
schedule["references_names"] = []

schedule["states"] = {}
# re-ordered to make type inference possible, but not sure the logic here
# is 100% sound (ignored type warnings both look like actual problems).
# keeping logic intact and ignoring warnings for now
sched_states = {}
if _state_text == ["inactive", "active"]:
for i, each in enumerate(_state_text):
schedule["states"][each] = i
sched_states[each] = i
presentValue = "{} ({})".format(
list(schedule["states"].keys())[int(presentValue.value)],
list(sched_states.keys())[int(presentValue.value)],
presentValue.value,
)
elif _state_text != "analog":
for i, each in enumerate(_state_text):
schedule["states"][each] = i + offset_MV
elif _state_text == "analog":
sched_states = _state_text # type: ignore[assignment]
presentValue = "{}".format(presentValue.value)
else:
try:
for i, each in enumerate(_state_text): # type: ignore[arg-type]
sched_states[each] = i + offset_MV
presentValue = "{} ({})".format(
list(schedule["states"].keys())[
list(sched_states.keys())[
int(presentValue.value) - offset_MV
],
presentValue.value,
)
except TypeError:
presentValue = presentValue.value
else:
schedule["states"] = _state_text
presentValue = "{}".format(presentValue.value)

schedule["states"] = sched_states
schedule["reliability"] = reliability
schedule["priority"] = priority
schedule["presentValue"] = presentValue
Expand Down

0 comments on commit 286b4ff

Please sign in to comment.