5
5
import typing
6
6
from typing import Any , Dict , Mapping , NamedTuple , Union
7
7
8
- import serial_asyncio
9
8
from amshan import obis_map
10
9
from amshan .meter_connection import (
11
10
AsyncConnectionFactory ,
12
11
ConnectionManager ,
13
12
MeterTransportProtocol ,
14
13
SmartMeterFrameContentProtocol ,
15
14
)
16
- import voluptuous as vol
17
-
18
15
from homeassistant .config_entries import ConfigEntry
19
16
from homeassistant .const import EVENT_HOMEASSISTANT_STOP
20
17
from homeassistant .core import callback
21
18
import homeassistant .helpers .config_validation as cv
22
19
from homeassistant .helpers .typing import ConfigType , EventType , HomeAssistantType
20
+ import serial_asyncio
21
+ import voluptuous as vol
23
22
24
23
from .const import (
25
24
CONF_SERIAL_BAUDRATE ,
32
31
CONF_SERIAL_XONXOFF ,
33
32
CONF_TCP_HOST ,
34
33
CONF_TCP_PORT ,
34
+ DOMAIN ,
35
35
ENTRY_DATA_MEASURE_CONNECTION ,
36
36
ENTRY_DATA_MEASURE_QUEUE ,
37
- DOMAIN ,
38
37
HOSTNAME_IP4_IP6_REGEX ,
39
38
)
40
39
@@ -87,7 +86,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
87
86
88
87
async def async_setup_entry (hass : HomeAssistantType , entry : ConfigEntry ) -> bool :
89
88
"""Set up amshan from a config entry."""
90
- measure_queue : "Queue[bytearray ]" = Queue (loop = hass .loop )
89
+ measure_queue : "Queue[bytes ]" = Queue (loop = hass .loop )
91
90
connection = setup_meter_connection (hass .loop , entry .data , measure_queue )
92
91
93
92
hass .data [DOMAIN ][entry .entry_id ] = {
@@ -128,7 +127,7 @@ async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> boo
128
127
129
128
130
129
async def async_close (
131
- measure_queue : "Queue[bytearray ]" , connection : ConnectionManager
130
+ measure_queue : "Queue[bytes ]" , connection : ConnectionManager
132
131
) -> None :
133
132
"""Close meter connection and measure processor."""
134
133
connection .close ()
@@ -138,19 +137,15 @@ async def async_close(
138
137
139
138
140
139
def setup_meter_connection (
141
- loop : AbstractEventLoop ,
142
- config : Mapping [str , Any ],
143
- measure_queue : "Queue[bytearray]" ,
140
+ loop : AbstractEventLoop , config : Mapping [str , Any ], measure_queue : "Queue[bytes]" ,
144
141
) -> ConnectionManager :
145
142
"""Initialize ConnectionManager using configured connection type."""
146
143
connection_factory = get_connection_factory (loop , config , measure_queue )
147
144
return ConnectionManager (connection_factory )
148
145
149
146
150
147
def get_connection_factory (
151
- loop : AbstractEventLoop ,
152
- config : Mapping [str , Any ],
153
- measure_queue : "Queue[bytearray]" ,
148
+ loop : AbstractEventLoop , config : Mapping [str , Any ], measure_queue : "Queue[bytes]" ,
154
149
) -> AsyncConnectionFactory :
155
150
"""Get connection factory based on configured connection type."""
156
151
0 commit comments