Skip to content

Commit fe16993

Browse files
benderlCopilot
authored andcommitted
Fix consumer modules (#3865)
* fix configuration type hints * fix consumer type hints and errors * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 31a46f4 commit fe16993

39 files changed

Lines changed: 155 additions & 135 deletions

File tree

packages/modules/consumers/askoma/askoheat/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
class AskoheatConfiguration:
1111
def __init__(self,
1212
ip_address: Optional[str] = None,
13-
port: Optional[int] = 502,
14-
modbus_id: Optional[int] = 1):
13+
port: int = 502,
14+
modbus_id: int = 1):
1515
self.ip_address = ip_address
1616
self.port = port
1717
self.modbus_id = modbus_id
@@ -23,7 +23,7 @@ def __init__(self,
2323
name: str = "Askoheat+",
2424
type: str = "askoheat",
2525
id: int = 0,
26-
configuration: AskoheatConfiguration = None,
26+
configuration: Optional[AskoheatConfiguration] = None,
2727
usage: Tuple[ConsumerUsage, ...] = (ConsumerUsage.SUSPENDABLE_TUNABLE,
2828
ConsumerUsage.METER_ONLY),
2929
**kwargs) -> None:

packages/modules/consumers/askoma/askoheat/consumer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22
import logging
3+
from typing import Optional
34
from modules.common.abstract_device import DeviceDescriptor
45
from modules.common.component_state import ConsumerState
56
from modules.common.component_type import ComponentType
@@ -12,8 +13,8 @@
1213

1314

1415
def create_consumer(config: Askoheat):
15-
client = None
16-
sim_counter = None
16+
client: Optional[ModbusTcpClient_] = None
17+
sim_counter: Optional[SimCounterConsumer] = None
1718

1819
def initializer():
1920
nonlocal client, sim_counter

packages/modules/consumers/avm/avm/config.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from typing import Optional, Tuple
2-
32
from control.consumer.consumer_data import ConsumerUsage
43
from helpermodules.auto_str import auto_str
54
from modules.common.consumer_setup import ConsumerSetup
@@ -13,7 +12,7 @@ def __init__(self,
1312
username: Optional[str] = None,
1413
password: Optional[str] = None,
1514
session_id: Optional[str] = None,
16-
session_mtime: Optional[str] = None,
15+
session_mtime: Optional[float] = None,
1716
name: Optional[str] = None) -> None:
1817
self.ip_address = ip_address
1918
self.username = username
@@ -29,7 +28,7 @@ def __init__(self,
2928
name: str = "AVM Fritz!Box",
3029
type: str = "avm",
3130
id: int = 0,
32-
configuration: AvmConfiguration = None,
31+
configuration: Optional[AvmConfiguration] = None,
3332
usage: Tuple[ConsumerUsage, ...] = (ConsumerUsage.SUSPENDABLE_TUNABLE,
3433
ConsumerUsage.METER_ONLY),
3534
**kwargs) -> None:

packages/modules/consumers/avm/avm/consumer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import time
55
import xml.etree.ElementTree as ET
6+
from typing import Optional
67

78
from dataclass_utils._dataclass_asdict import asdict
89
from helpermodules.pub import Pub
@@ -18,7 +19,7 @@
1819

1920

2021
def create_consumer(config: Avm):
21-
ain = None # Actuator Identification Number
22+
ain: Optional[str] = None # Actuator Identification Number
2223

2324
def update() -> ConsumerState:
2425
nonlocal ain
@@ -61,6 +62,9 @@ def update() -> ConsumerState:
6162
state=state,
6263
voltages=voltages
6364
)
65+
raise RuntimeError(
66+
f"Device with name '{config.configuration.name}' was not found or is not currently available"
67+
)
6468

6569
def ensure_valid_session_id():
6670
if check_valid_session_id() is False:

packages/modules/consumers/generic/dac/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
class DacConfiguration:
1212
def __init__(self,
1313
ip_address: Optional[str] = None,
14-
port: Optional[int] = 502,
15-
modbus_id: Optional[int] = 1,
14+
port: int = 502,
15+
modbus_id: int = 1,
1616
model: Model = Model.N4Dac02):
1717
self.ip_address = ip_address
1818
self.port = port
@@ -26,7 +26,7 @@ def __init__(self,
2626
name: str = "Digital-Analog-Konverter (DAC) 0.01V bis 10.0V",
2727
type: str = "dac",
2828
id: int = 0,
29-
configuration: DacConfiguration = None,
29+
configuration: Optional[DacConfiguration] = None,
3030
usage: Tuple[ConsumerUsage, ...] = (ConsumerUsage.SUSPENDABLE_TUNABLE,),
3131
**kwargs) -> None:
3232
super().__init__(name, type, id, vendor=vendor_descriptor.configuration_factory(

packages/modules/consumers/generic/dac/consumer.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22
import logging
3+
from typing import Optional
34
from modules.common.abstract_device import DeviceDescriptor
45
from modules.common.component_type import ComponentType
56
from modules.common.configurable_consumer import ConfigurableConsumer, SetLimitData
@@ -12,8 +13,8 @@
1213

1314

1415
def create_consumer(config: Dac):
15-
client: ModbusTcpClient_ = None
16-
sim_counter = None
16+
client: Optional[ModbusTcpClient_] = None
17+
sim_counter: Optional[SimCounterConsumer] = None
1718

1819
def initializer():
1920
nonlocal client, sim_counter
@@ -31,18 +32,18 @@ def set_power_limit(power_limit: float, data: SetLimitData) -> None:
3132
elif config.configuration.model == Model.DA02:
3233
client.write_register(0x01f4, power_limit * 4000 / data.max_power, ModbusDataType.INT_16, unit=modbus_id)
3334
elif config.configuration.model == Model.M120T:
34-
# ausgabe nicht kleiner 0,9V sonst Leistungsregelung der WP aus
35+
# Ausgabe nicht kleiner 0,9V sonst Leistungsregelung der WP aus
3536
power_limit = max(power_limit * 4095 / data.max_power, 370)
3637
client.write_register(0x01f4, power_limit, ModbusDataType.INT_16, unit=modbus_id)
3738
elif config.configuration.model == Model.AA02B:
3839
power_limit = max((power_limit * (4095-820) / data.max_power)+820, 820)
39-
# ausgabe nicht kleiner 4ma sonst Leistungsregelung der WP aus
40+
# Ausgabe nicht kleiner 4ma sonst Leistungsregelung der WP aus
4041
client.write_register(0x01f4, power_limit, ModbusDataType.INT_16, unit=modbus_id)
4142

4243
return ConfigurableConsumer(consumer_config=config,
4344
initializer=initializer,
4445
error_handler=error_handler,
45-
set_power_limit=set_power_limit,)
46+
set_power_limit=set_power_limit)
4647

4748

4849
device_descriptor = DeviceDescriptor(configuration_factory=Dac)

packages/modules/consumers/generic/http/config.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from typing import Tuple
2-
1+
from typing import Tuple, Optional
32
from control.consumer.consumer_data import ConsumerUsage
43
from helpermodules.auto_str import auto_str
54
from modules.common.consumer_setup import ConsumerSetup
@@ -9,17 +8,17 @@
98
@auto_str
109
class HttpConfiguration:
1110
def __init__(self,
12-
url: str = None,
13-
current_l1_path: str = None,
14-
current_l2_path: str = None,
15-
current_l3_path: str = None,
16-
power_path: str = None,
17-
temperatures_path: str = None,
18-
imported_path: str = None,
19-
exported_path: str = None,
20-
switch_on_path: str = None,
21-
switch_off_path: str = None,
22-
set_power_limit_path: str = None):
11+
url: Optional[str] = None,
12+
current_l1_path: Optional[str] = None,
13+
current_l2_path: Optional[str] = None,
14+
current_l3_path: Optional[str] = None,
15+
power_path: Optional[str] = None,
16+
temperatures_path: Optional[str] = None,
17+
imported_path: Optional[str] = None,
18+
exported_path: Optional[str] = None,
19+
switch_on_path: Optional[str] = None,
20+
switch_off_path: Optional[str] = None,
21+
set_power_limit_path: Optional[str] = None):
2322
self.url = url
2423
self.current_l1_path = current_l1_path
2524
self.current_l2_path = current_l2_path
@@ -39,7 +38,7 @@ def __init__(self,
3938
name: str = "HTTP-Verbraucher",
4039
type: str = "http",
4140
id: int = 0,
42-
configuration: HttpConfiguration = None,
41+
configuration: Optional[HttpConfiguration] = None,
4342
usage: Tuple[ConsumerUsage, ...] = (ConsumerUsage.METER_ONLY,
4443
ConsumerUsage.CONTINUOUS,
4544
ConsumerUsage.SUSPENDABLE_ONOFF,

packages/modules/consumers/generic/http/consumer.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22
import logging
3+
from typing import Optional, Callable
34

45
from modules.common import req
56
from modules.common.abstract_device import DeviceDescriptor
@@ -14,16 +15,16 @@
1415

1516

1617
def create_consumer(config: Http):
17-
session = None
18-
sim_counter = None
19-
get_power = None
20-
get_imported = None
21-
get_exported = None
22-
get_currents = None
23-
get_temperatures = None
24-
post_set_power_limit = None
25-
post_switch_on = None
26-
post_switch_off = None
18+
session: Optional[req.CustomSession] = None
19+
sim_counter: Optional[SimCounterConsumer] = None
20+
get_power: Optional[Callable] = None
21+
get_imported: Optional[Callable] = None
22+
get_exported: Optional[Callable] = None
23+
get_currents: Optional[Callable] = None
24+
get_temperatures: Optional[Callable] = None
25+
post_set_power_limit: Optional[Callable] = None
26+
post_switch_on: Optional[Callable] = None
27+
post_switch_off: Optional[Callable] = None
2728

2829
def initializer():
2930
nonlocal session, sim_counter
@@ -65,15 +66,15 @@ def update() -> None:
6566

6667
def switch_on():
6768
# Authorization?
68-
post_switch_on(session, params={"state": True})
69+
post_switch_on(session, {"state": True})
6970

7071
def switch_off():
7172
# Authorization?
72-
post_switch_off(session, params={"state": False})
73+
post_switch_off(session, {"state": False})
7374

7475
def set_power_limit(power_limit: float, data: SetLimitData) -> None:
7576
# Authorization?
76-
post_set_power_limit(session, params={"power_limit": power_limit})
77+
post_set_power_limit(session, {"power_limit": power_limit})
7778

7879
return ConfigurableConsumer(consumer_config=config,
7980
initializer=initializer,

packages/modules/consumers/generic/json/config.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Tuple
1+
from typing import Tuple, Optional
22

33
from control.consumer.consumer_data import ConsumerUsage
44
from helpermodules.auto_str import auto_str
@@ -9,17 +9,17 @@
99
@auto_str
1010
class JsonConfiguration:
1111
def __init__(self,
12-
url: str = None,
13-
jq_current_l1: str = None,
14-
jq_current_l2: str = None,
15-
jq_current_l3: str = None,
16-
jq_power: str = None,
17-
jq_temperatures: str = None,
18-
jq_imported: str = None,
19-
jq_exported: str = None,
20-
jq_switch_on: str = None,
21-
jq_switch_off: str = None,
22-
jq_set_power_limit: str = None):
12+
url: Optional[str] = None,
13+
jq_current_l1: Optional[str] = None,
14+
jq_current_l2: Optional[str] = None,
15+
jq_current_l3: Optional[str] = None,
16+
jq_power: Optional[str] = None,
17+
jq_temperatures: Optional[str] = None,
18+
jq_imported: Optional[str] = None,
19+
jq_exported: Optional[str] = None,
20+
jq_switch_on: Optional[str] = None,
21+
jq_switch_off: Optional[str] = None,
22+
jq_set_power_limit: Optional[str] = None):
2323
self.url = url
2424
self.jq_currents = (jq_current_l1, jq_current_l2, jq_current_l3)
2525
self.jq_power = jq_power
@@ -37,7 +37,7 @@ def __init__(self,
3737
name: str = "JSON-Verbraucher",
3838
type: str = "json",
3939
id: int = 0,
40-
configuration: JsonConfiguration = None,
40+
configuration: Optional[JsonConfiguration] = None,
4141
usage: Tuple[ConsumerUsage, ...] = (ConsumerUsage.METER_ONLY,
4242
ConsumerUsage.CONTINUOUS,
4343
ConsumerUsage.SUSPENDABLE_ONOFF,

packages/modules/consumers/generic/json/consumer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616

1717
def create_consumer(config: Json):
18-
session = None
19-
sim_counter = None
18+
session: Optional[req.CustomSession] = None
19+
sim_counter: Optional[SimCounterConsumer] = None
2020
jq_power = None
2121
jq_imported = None
2222
jq_exported = None
@@ -57,7 +57,7 @@ def initializer():
5757
jq_switch_on = create_post_function(config.configuration.jq_switch_on)
5858
jq_switch_off = create_post_function(config.configuration.jq_switch_off)
5959

60-
def update() -> None:
60+
def update() -> ConsumerState:
6161
response = req.get_http_session().get(config.configuration.url, timeout=5).json()
6262
power = float(jq_power.input(response).first())
6363
temperatures = float(jq_temperatures.input(response).first()) if jq_temperatures is not None else None

0 commit comments

Comments
 (0)