@@ -182,6 +182,11 @@ async def _get_association_state(self):
182182 async def send_packet (self , packet : zigpy .types .ZigbeePacket ) -> None :
183183 LOGGER .debug ("Sending packet %r" , packet )
184184
185+ try :
186+ device = self .get_device_with_address (packet .dst )
187+ except (KeyError , ValueError ):
188+ device = None
189+
185190 tx_opts = TXOptions .NONE
186191
187192 if packet .extended_timeout :
@@ -193,17 +198,25 @@ async def send_packet(self, packet: zigpy.types.ZigbeePacket) -> None:
193198 long_addr = UNKNOWN_IEEE
194199 short_addr = UNKNOWN_NWK
195200
196- if packet .dst .addr_mode == zigpy .types .AddrMode .IEEE :
197- long_addr = packet .dst .address
198- elif packet .dst .addr_mode == zigpy .types .AddrMode .Broadcast :
201+ if packet .dst .addr_mode == zigpy .types .AddrMode .Broadcast :
199202 long_addr = EUI64 (
200203 [
201204 zigpy .types .uint8_t (b )
202205 for b in packet .dst .address .to_bytes (8 , "little" )
203206 ]
204207 )
205- else :
206208 short_addr = packet .dst .address
209+ elif packet .dst .addr_mode == zigpy .types .AddrMode .Group :
210+ short_addr = packet .dst .address
211+ elif packet .dst .addr_mode == zigpy .types .AddrMode .IEEE :
212+ long_addr = EUI64 (packet .dst .address )
213+ elif device is not None :
214+ long_addr = EUI64 (device .ieee )
215+ short_addr = device .nwk
216+ else :
217+ raise zigpy .exceptions .DeliveryError (
218+ "Cannot send a packet to a device without a known IEEE address"
219+ )
207220
208221 send_req = self ._api .tx_explicit (
209222 long_addr ,
0 commit comments