rytilahti / python-miio

Python library & console tool for controlling Xiaomi smart appliances
https://python-miio.readthedocs.io
GNU General Public License v3.0
3.75k stars 561 forks source link

[Simulator Usage] AttributeError: 'SimulatedMiio' object has no attribute 'encode' #1789

Closed tao2years closed 1 year ago

tao2years commented 1 year ago

Describe the bug When I use the cmd "miiocli devtools miio-simulator --file miio/integrations/zhimi/fan/zhimi_fan.yaml" to create a simulator, it reports the ERROR “AttributeError: 'SimulatedMiio' object has no attribute 'encode' ”

Version information (please complete the following information):

Device information: None

To Reproduce

  1. miiocli devtools miio-simulator --file filepath

Expected behavior A simulator created

Console output


INFO     Available models:                                  miiosimulator.py:154
         [MiioModel(model='zhimi.fan.sa1', name='unknown                        
         name'), MiioModel(model='zhimi.fan.za1',                               
         name='unknown name'),                                                  
         MiioModel(model='zhimi.fan.za3', name='unknown                         
         name'), MiioModel(model='zhimi.fan.za4',                               
         name='unknown name'),                                                  
         MiioModel(model='zhimi.fan.v3', name='unknown                          
         name'), MiioModel(model='zhimi.fan.v2',                                
         name='unknown name')]                                                  
ERROR    Exception: 'SimulatedMiio' object has no attribute   click_common.py:56
         'encode'                                                               
         Traceback (most recent call last):                                     
           File "/home/taos/anaconda3/envs/ha/lib/python3.11/                   
         site-packages/miio/click_common.py", line 54, in                       
         __call__                                                               
             return self.main(*args, **kwargs)                                  
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^                                  
           File "/home/taos/anaconda3/envs/ha/lib/python3.11/                   
         site-packages/click/core.py", line 1055, in main                       
             rv = self.invoke(ctx)                                              
                  ^^^^^^^^^^^^^^^^                                              
           File "/home/taos/anaconda3/envs/ha/lib/python3.11/                   
         site-packages/click/core.py", line 1657, in invoke                     
             return                                                             
         _process_result(sub_ctx.command.invoke(sub_ctx))                       
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^                   
         ^^^^^^                                                                 
           File "/home/taos/anaconda3/envs/ha/lib/python3.11/                   
         site-packages/click/core.py", line 1657, in invoke                     
             return                                                             
         _process_result(sub_ctx.command.invoke(sub_ctx))                       
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^                   
         ^^^^^^                                                                 
           File "/home/taos/anaconda3/envs/ha/lib/python3.11/                   
         site-packages/click/core.py", line 1404, in invoke                     
             return ctx.invoke(self.callback, **ctx.params)                     
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                     
           File "/home/taos/anaconda3/envs/ha/lib/python3.11/                   
         site-packages/click/core.py", line 760, in invoke                      
             return __callback(*args, **kwargs)                                 
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^                                 
           File "/home/taos/anaconda3/envs/ha/lib/python3.11/                   
         site-packages/miio/devtools/simulators/miiosimulator                   
         .py", line 158, in miio_simulator                                      
             loop.run_until_complete(main(dev))                                 
           File "/home/taos/anaconda3/envs/ha/lib/python3.11/                   
         asyncio/base_events.py", line 653, in                                  
         run_until_complete                                                     
             return future.result()                                             
                    ^^^^^^^^^^^^^^^                                             
           File "/home/taos/anaconda3/envs/ha/lib/python3.11/                   
         site-packages/miio/devtools/simulators/miiosimulator                   
         .py", line 138, in main                                                
             did, mac = did_and_mac_for_model(dev)                              
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^                              
           File "/home/taos/anaconda3/envs/ha/lib/python3.11/                   
         site-packages/miio/devtools/simulators/common.py",                     
         line 36, in did_and_mac_for_model                                      
             m.update(model.encode())                                           
                      ^^^^^^^^^^^^                                              
         AttributeError: 'SimulatedMiio' object has no                          
         attribute 'encode' 
rytilahti commented 1 year ago

The linked PR should fix this, looks like you are the first person to try the simulator out, thanks for the report! :-)

❯ miiocli devtools miio-simulator --file miio/integrations/zhimi/fan/zhimi_fan.yaml
INFO     Available models: [MiioModel(model='zhimi.fan.sa1', name='unknown name'), MiioModel(model='zhimi.fan.za1', name='unknown name'),              
         MiioModel(model='zhimi.fan.za3', name='unknown name'), MiioModel(model='zhimi.fan.za4', name='unknown name'), MiioModel(model='zhimi.fan.v3', 
         name='unknown name'), MiioModel(model='zhimi.fan.v2', name='unknown name')]                                                                   
WARNING  No --model defined, using the first supported one: zhimi.fan.sa1                                                                              
INFO     Miio push server started with address=0.0.0.0 server_id=1718865432                                                                            
❯ miiocli fan --ip 127.0.0.1 --token 00000000000000000000000000000000 status
Running command status
rw- Power (FanStatus.is_on): True
rw- LED Brightness (FanStatus.led_brightness): LedBrightness.Bright
rw- Buzzer (FanStatus.buzzer): False
rw- Child Lock (FanStatus.child_lock): False
rw- Natural Speed Level (FanStatus.natural_speed): 2
rw- Direct Speed (FanStatus.direct_speed): 1
rw- Oscillate (FanStatus.oscillate): False
r-- AC Powered (FanStatus.ac_power): True
r-- Motor Speed (FanStatus.speed): 277 RPM
rw- Oscillation Angle (FanStatus.angle): 120