ioBroker / ioBroker.js-controller

ioBroker controller
http://iobroker.net
MIT License
294 stars 58 forks source link

CLI: Get (plain) value of binary state leads to error #1675

Closed klein0r closed 2 years ago

klein0r commented 2 years ago

Describe the bug

CLI commands return errors for binary states:

To Reproduce

  1. Create a state with type file
  2. Use setBinaryState to store binary information (like an image)
  3. run iobroker state get <yourStateId> or iobroker state getplain <yourStateId> on cli

Example:

iobroker state get sayit.0.tts.mp3
 Cannot parse "��D�Rp������?Qsh8BL:'�O�߳�릢m=2�Q�
�*ӛ�M�����ps����4g��T�
                      *
                      2S�&B
                           G��4���D��6x2Rp�8&<�<= t����U��둆��.+a�F��B׋}td��&�D��`B���O"P�~%Q
                                                                                             I��2��{��1A
���D��Έ2R��.*3j��d2
7�c��C�_���ډй�bC   �`h%"Hml�iԫ���5w��esԠ�̝l{�/�~�ed�I馨T��hc�����CɪC�*�X� ��D�   ɖ�����S�"T�(ϥ�a��|iݠ9Q&t`�P>U�R

�^�<�/���=U�C�3���=�ThB��D�
                           ���L�
��i��D�9��2R�%]�Ԟԧ���5��g����N�$d�$b�$�sQ���됱-%2E>B=<���'���1�.>z ��
  �p��/�o������7���H#
!R��̔��G̸���������$���jS�;i� �D�
                           a�h���&$`& ���3�6�B�&��r���K:�����օ}�BP%��E���D�
                                                                           Q:���p�[�ۂz�[L���������W덉��@�!i"i��� ai^��X6,2ec��s~歶�o���N�5z�f 6�q݋���D�
                                                                                                                                                       �z������J��u$S#�
       ���?@���d٭��ѧ��Ac�L�\�F�U�.��Y�V�v��.�X{n�D珐C?���O�B��������D����֔�<`�H�4��\Ue��I����3���D�&�<���?@���K���O�B������uU�eb$�ԩHM�����������b����D^���d��w#�P)sD����R�Z�X+vQ#��U7�����e<L�W�<��6��^4�Z�(eW��U�w����*�:b�WH��-4���D�Q*��Lp��k��l�e�+Y4���%��9�
                                                                                                �$�N��nc��#��T�
�v���˟��s,��98`�iRٵ�3�������D�*���q8��0��z�{ E�E%��5��=����^�&N��L|��9ۺ���Ad),�'N����[�� <�f��l�5�H��#e��e����D�(����F��z   �       Yփ%�!��^?(�d�៿Ϝ�
                                                                                                                                                               ���y������n%���[�&g���*$��G�\��4�����D�8y^��
�q
  L](��������H����# \B���   �ԧT��k�Ç

�;#MɭRJ���D�IA^��̔�`���q���
�Z�k �%׿��2��
             ��^���;��X����(h���A��*
                                    �W�����Z�V↜�m�*�{
                                                     4T��D�W�:���p�K���{4Xψ�N�%���Gδ†�b���owc
��?qm&L���
          �d�8�������E��8_ڣ�F�ڌ�ɚ��M�i���D�c��̒pu\>� �B|�h��!�:f���.��\:#�P�
 Sm�E�{^�������
               =~YiJ�j�~����q`���݊z�q��D�ji��VpH֫
��:���z�4�F�*KX��W��?
                     ��-�:��{��?���R�x�҅.ʬ0D�.e2�2���30�:�]+K�ė`��D�k�ʘ�Pp
��ɼRN��                                                                  >�djG/��怲�����e����2��*(aػ"]���T
6���@��=%b㄁�
            ��D�sp��ְH�2cLrFt�n~������ռ����}.��-���������С �݇.,4aTU��DV��
�Q��JA����&�R�"�*\\2"NT��D�tJ���D�'
                                   �.�UL�)�������՛���������eV,����:��"մ�
%���QB�g���J?��36ۜ^Ɂ!oK��hS��n��D�u�҈�D���6��@���X������\�'&X>��H Ȁ�����ҧ
�x�!zU�o��I� ��Q�گW���f��r�Y({�X�
�4:�    i
%��D�tr�޲HVt��)}����o��ۭJ��[������
                                 �Agي*ʓ ����hC@
                                               ��P8<�����Q0�]�+�,�B
r�G}�?8���D�zIҌԄ�#��R�
                      4���� ���K���0.�KT��Z&8���\���,ҕ5n��Ծ��e%��$�p�gW�������wޏ���7�Q0���Dă����^L��*�������FU�C
                                                                                                                    �D���b���XI�lZ�W    �!��#'�n1
                                                                                                                                                 �6�70m�D:��M�@m��'�R����[⶝6��D���^H��R�:�@��H��ms@�,Qȷֈ9L
x"�>8D�ʬPB�A�V�
��DĤ�~|�HQ=R��N�V���(C���<�,�V���I^���Qb�%�ް��]T��EP��ƂY��F��];�*_���^�Q�7G0�&e��P�C���Dijp�x�L�ճI�o����Z���&r��B�8�h�DM�\���:�Qq
P�TH(H
�����B����4$��Q�[#�"R@�#������pZ���
                                  TD%"D��?�z��,�'N�:=c����D����l�H�����ܵ�LAME3.100UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUULAME3.��D���,��L100UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUULAME3.��D��H��1�L100UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUULAME3.��DĬH100UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUW+Y�T���DĬH�
��(���z��pN���c�Կ��v�eI�G�Ą����~V8���
�,v_�S�EJڱp�V�z����L"���C�4#���N�T���8��FF:<���+�d�(a�-,��}�f_��DĬH��8�hٳ=�
��>Kʺ4($j�I���,aI��5��aV+Bac�`���UR�
�P�X؛������q�
��LAME3.100UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU��D�����xƔUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU��D����y�MUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU"
The state sayit.0.tts.mp3 was not found!
klein0r commented 2 years ago

Expected behaviour:

iobroker state getplain sayit.0.tts.mp3 > sayit.mp3

should work

klein0r commented 2 years ago

See also https://github.com/ioBroker/ioBroker.simple-api/issues/111

foxriver76 commented 2 years ago

Makes sense, thanks for reporting.

Apollon77 commented 2 years ago

Or we introduce a "get-binary" command or such?

foxriver76 commented 2 years ago

Or we introduce a "get-binary" command or such?

Or read the object first and check for obj.binary if so getbinary state, else get state and do the formatting stuff

foxriver76 commented 2 years ago

But yes, I think get binary would be cleaner and maybe someone wants set binary later on in the process

klein0r commented 2 years ago

But yes, I think get binary would be cleaner and maybe someone wants set binary later on in the process

The question is, what get and getplain should return for binary states.

If you provide an additional getbinary command, the user has to know about the difference between "normal" and "binary" states. Is that something a common user has to know?

foxriver76 commented 2 years ago

Yes, in an optimal world we take care of this. Will cost some performance but not relevant for cli.

User discussion, maybe.. who uses cli ;-)

foxriver76 commented 2 years ago

I have created a PR. We should discuss if a separate command makes more sense, both are "called" states but are very different in their concepts. A binary state has no attributes like a timestamp ack etc. It is always just a Buffer. Regarding output it could also be necessary to specify the encoding as mentioned in comment https://github.com/ioBroker/ioBroker.js-controller/pull/1677#discussion_r785432261

Apollon77 commented 2 years ago

As already mentioned on the PR I think it is best to "Break" here because it never really worked in the contet was not utf-8. The state get command will get an error on binary states.

Additionally we introduce a iob state get-binary <id> <encoding> to allow a clean binary stat ehandling and can also support to output as hex or base64 or such using that way. We also could then add a iob state set-binary <id> <encoding> Where data are read from stdin afterwards and processed as the given encoding.

Opinions?