gickowtf / pixoo-homeassistant

Home Assistant Integration for Divoom Pixoo 64
MIT License
112 stars 12 forks source link

[Feature] Config restructure. #28

Closed Mrredstone5230 closed 6 months ago

Mrredstone5230 commented 6 months ago

This is my implementation of it. This is still not finished. I still need to update the "push notification service" and the config migration code.

(Please note that this is indeed based of of the "enable-tag" branch)

Also, it has been structured and tested with this config: (except that the Fuel and PV page weren't actually tested)

- page_type: PV
  power: "{{ states.sensor.YOUR_SENSOR.state }}"
  storage: "{{ states.sensor.YOUR_SENSOR.state }}"
  discharge: "{{ states.sensor.YOUR_SENSOR.state }}"
  powerhousetotal: "{{ states.sensor.YOUR_SENSOR.state }}"   
  vomNetz: "{{ states.sensor.YOUR_SENSOR.state }}"
  time: "{{ now().strftime('%H:%M') }}"  #Format HH:MM

#etc for the PV page, for example.

- page_type: components  #or custom, I'm not sure what's better because of Custom Channels..
  components:
  - type: text
    position: [0, 10]
    content: "github/gickowtf"
    font: PICO_8
    color: [255, 0, 0] # or write "red"

  - type: text
    position: [17, 18]
    content: '{{ states.sensor.YOUR_SENSOR.state }}'
    color: '{{ "red" if float(states.sensor.YOUR_SENSOR.state) <= 1 else "green"}}'
    font: PICO_8

  - type: image
    position: [1, 16]
    image_path: '{% set num = float(states.input_number.test.state) %} {% if num >= 80 %} /config/custom_components/divoom_pixoo/img/akku80-100.png {% elif num >= 100 %} /config/custom_components/divoom_pixoo/img/akku60-80.png {% else %} /config/custom_components/divoom_pixoo/img/akku40-60.png {% endif %}'
# This is just an example with Templates. The old PV page would still work (as shown above).

- page_type: channel
  id: 2

- page_type: clock
  enabled: False  # This would disable the integration to render the page. Of course, this would accept Templates. This 'tag' would True by default (and of course optional), and be available for every page.
  id: 39

(The color names are also based of of https://github.com/paztronomer/blog/blob/master/code/p01_python_colors/named_colors.png)

Closes #17

gickowtf commented 6 months ago

I've just skimmed through it. I think it's really brilliant. But unfortunately I can't take a closer look until tonight. I'm too busy with other projects.

Mrredstone5230 commented 6 months ago

No worries! It's not finished anyways, so there's no stress.

gickowtf commented 6 months ago

i just tested it. unfortunately there seems to be an error with the enable tag. i have my config so that i get page 1 displayed page 2 should not be displayed but is displayed for 30 seconds and page 3 which should be displayed again is not displayed at all. otherwise i find the spelling of the config clearly nicer.

gickowtf commented 6 months ago

I don't know why but in my PR #27 every page that should be displayed is shown for exactly 15 seconds... but unfortunately I can't recognize the error right away.

Mrredstone5230 commented 6 months ago

Do you mind sharing your config? I didn't really change anything from your code..

gickowtf commented 6 months ago

I will simply merge my PR #27 tomorrow. So that the sensor.py is up to date. Sorry it's way too late again. Last week I was on vacation and definitely had more time.

Mrredstone5230 commented 6 months ago

Alright, I tested a lot and I redid a bit of the logic. @gickowtf could you try again with your config?

(Completely unrelated, but I also realized that you can completely disable the page "changing" logic entirely if you disable the sensor entity in HA. Pretty cool!)

Mrredstone5230 commented 6 months ago

Just remade/updated the service. Hope you like it!

gickowtf commented 6 months ago

ok the push service works perfectly without having looked at the code beforehand, I thought that it was now also possible to push PV, Fuel or Clockid. So I almost said it doesn't work. But with the component it worked very well in the end.

page_type: components  #or custom, I'm not sure what's better because of Custom Channels..
components:
  - type: text
    position: [0, 10]
    content: "github/gickowtf"
    font: PICO_8
    color: [255, 0, 0] # or write "red"

The page display now also works as desired :D Great work. I really like it very much :

I have tested it with these configs:

- page_type: components  #or custom, I'm not sure what's better because of Custom Channels..
  enabled: "{{ states.input_boolean.test.state }}"
  components:
  - type: text
    position: [0, 10]
    content: "1 github/gickowtf"
    font: PICO_8
    color: [255, 0, 0] # or write "red"
- page_type: components  #or custom, I'm not sure what's better because of Custom Channels..
  enabled: "{{ states.input_boolean.test2.state }}"
  components:
  - type: text
    position: [0, 10]
    content: "2 github/gickowtf"
    font: PICO_8
    color: [255, 0, 0] # or write "red"
- page_type: components  #or custom, I'm not sure what's better because of Custom Channels..
  enabled: "{{ states.input_boolean.test.state }}"
  components:
  - type: text
    position: [0, 10]
    content: "3 github/gickowtf"
    font: PICO_8
    color: [255, 0, 0] # or write "red"
- page_type: Fuel
  enabled: "{{ states.input_boolean.test.state }}"
  title: Classic
  name1: Diesel
  price1: "{{ states.sensor.diesel.state }}"
  name2: Super
  price2: "{{ states.sensor.super.state }}"
  name3: E10
  price3: "{{ states.sensor.e10.state }}"
  status: >-
    {% if is_state('binary_sensor.status', 'on') %} Offen {%
    else %} Geschlossen {% endif %}
  title_offset: 10
- page_type: PV
  enabled: "{{ states.input_boolean.test2.state }}"
  power: "{{ states.sensor.power.state }}"
  storage: "{{ states.sensor.battery_percent.state }}"
  discharge: "{{ states.sensor.battery_power.state }}"
  powerhousetotal: "{{ states.power_house_total.state }}"
  vomNetz: "{{ states.sensor.power_external_total.state }}"
  time: "{{ now().strftime('%H:%M') }}"
- page_type: clock
  enabled: "{{ states.input_boolean.test.state }}"
  id: 182
gickowtf commented 6 months ago

give me a sign when you are done then I would like to merge this. I like it very much - as always a thousand thanks for your help

gickowtf commented 6 months ago

sorry for deleting my branch enable tag i restored it and reopened your PR

Mrredstone5230 commented 6 months ago

sorry for deleting my branch enable tag i restored it and reopened your PR

(You should be able to delete the branch now. I changed the PR to go to main now)

Mrredstone5230 commented 6 months ago

ok the push service works perfectly without having looked at the code beforehand, I thought that it was now also possible to push PV, Fuel or Clockid. So I almost said it doesn't work. But with the component it worked very well in the end.

page_type: components  #or custom, I'm not sure what's better because of Custom Channels..
components:
  - type: text
    position: [0, 10]
    content: "github/gickowtf"
    font: PICO_8
    color: [255, 0, 0] # or write "red"

The page display now also works as desired :D Great work. I really like it very much :

I have tested it with these configs:

- page_type: components  #or custom, I'm not sure what's better because of Custom Channels..
  enabled: "{{ states.input_boolean.test.state }}"
  components:
  - type: text
    position: [0, 10]
    content: "1 github/gickowtf"
    font: PICO_8
    color: [255, 0, 0] # or write "red"
- page_type: components  #or custom, I'm not sure what's better because of Custom Channels..
  enabled: "{{ states.input_boolean.test2.state }}"
  components:
  - type: text
    position: [0, 10]
    content: "2 github/gickowtf"
    font: PICO_8
    color: [255, 0, 0] # or write "red"
- page_type: components  #or custom, I'm not sure what's better because of Custom Channels..
  enabled: "{{ states.input_boolean.test.state }}"
  components:
  - type: text
    position: [0, 10]
    content: "3 github/gickowtf"
    font: PICO_8
    color: [255, 0, 0] # or write "red"
- page_type: Fuel
  enabled: "{{ states.input_boolean.test.state }}"
  title: Classic
  name1: Diesel
  price1: "{{ states.sensor.diesel.state }}"
  name2: Super
  price2: "{{ states.sensor.super.state }}"
  name3: E10
  price3: "{{ states.sensor.e10.state }}"
  status: >-
    {% if is_state('binary_sensor.status', 'on') %} Offen {%
    else %} Geschlossen {% endif %}
  title_offset: 10
- page_type: PV
  enabled: "{{ states.input_boolean.test2.state }}"
  power: "{{ states.sensor.power.state }}"
  storage: "{{ states.sensor.battery_percent.state }}"
  discharge: "{{ states.sensor.battery_power.state }}"
  powerhousetotal: "{{ states.power_house_total.state }}"
  vomNetz: "{{ states.sensor.power_external_total.state }}"
  time: "{{ now().strftime('%H:%M') }}"
- page_type: clock
  enabled: "{{ states.input_boolean.test.state }}"
  id: 182

I was impressed that the Fuel and PV page didn't work, as they technically should have. But, turns out HA renders the templates before even passing it to the integration, so it gave an 'int' to the template renderer, which wouldn't work. It should be fixed, and I'm happy you like it!

ireneybean commented 6 months ago

Probably a good idea to update the README too. :-)

gickowtf commented 6 months ago

Of course I'll adapt the readme accordingly when the time comes.

gickowtf commented 6 months ago

i am currently adapting the entire readme or rewriting it for your PR. i noticed that the newline support {{\n}} no longer works. "template error".

      content: |-
        text1 on first line
        text2 on second line

The good thing about rewriting the readme is that I'm really testing everything once :D

Mrredstone5230 commented 6 months ago

i am currently adapting the entire readme or rewriting it for your PR. i noticed that the newline support {{\n}} no longer works. "template error".

      content: |-
        text1 on first line
        text2 on second line

The good thing about rewriting the readme is that I'm really testing everything once :D

Yeahh, I just tested it and it did that. You HAVE to put {{'\n'}} with the ' , or else it won't really work. I'm not sure why, but that's a fix...

gickowtf commented 6 months ago

Yeahh, I just tested it and it did that. You HAVE to put {{'\n'}} with the ' , or else it won't really work. I'm not sure why, but that's a fix...

No problem, I think it's even better the way it is now

      content: |-
        text1 on first line
        text2 on second line
gickowtf commented 6 months ago

So I have really tested everything completely once. I couldn't find any new errors and I have to say I'm very impressed. Really very good work. I have prepared the readme in #30

Mrredstone5230 commented 6 months ago

Alright, just added a migration feature. It will basically auto update old config-entry users, but it can also allow users that update from the old configuration.yaml era to use the migration tool (with the async_detect_and_fix_old_entry method). I've included an old configuration down here to test if you want. (please test this feature!!!) ((And I'm sorry Irene, it's full of if/elif)

Also, this could break your config entries (gicko and irene), since you already used the new config style before I updated the "CURRENT_ENTRY_VERSION" to 2. This will/should not happen to end-users.

- page: 1
  PV:
    - power: "{{ states.sensor.YOUR_SENSOR.state }}"
      storage: "{{ states.sensor.YOUR_SENSOR.state }}"
      discharge: "{{ states.sensor.YOUR_SENSOR.state }}"
      powerhousetotal: "{{ states.sensor.YOUR_SENSOR.state }}"
      vomNetz: "{{ states.sensor.YOUR_SENSOR.state }}"
      time: "{{ now().strftime('%H:%M') }}"
- page: 2
  texts:
    - text: github/gickowtf
      position:
        - 0
        - 10
      font: FONT_PICO_8
      font_color:
        - 255
        - 0
        - 0
    - text: Thx 4 Support
      position:
        - 0
        - 30
      font: FONT_PICO_8
      font_color:
        - 255
        - 0
        - 0
  images:
    - image: /config/custom_components/divoom_pixoo/img/haus.png
      position:
        - 30
        - 10
- page: 3
  channel:
    - number: 2
- page: 4
  clockId:
    - number: 39

With that, I think the new config style is complete. (Maybe Irene's RenderFactory could be implemented later on??). Hope you like it!

Mrredstone5230 commented 6 months ago

@gickowtf If you want, I can give you access to push your new README to my branch. This will allow all modifications to be in the same PR.

Mrredstone5230 commented 6 months ago

Alright, I merged your readme branch in mine. You could close #30 I think.

gickowtf commented 6 months ago

Just create a new release and then that should be it. a thousand thanks again ... let me know what I can do for you.

Mrredstone5230 commented 6 months ago

Nice, thanks for merging. I'm not sure I understood correctly, but I unfortunately cannot create releases myself. For that I would need to be a "maintainer" I think...

gickowtf commented 6 months ago

@Mrredstone5230 No problem, I think it's because of my English. I have now created a new release 1.7.0 and loaded version 1.4.2 with your old config. What can I say, it worked. Brilliant