Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes to energy sources behavior #20785

Merged
merged 1 commit into from May 13, 2024

Conversation

karwosts
Copy link
Contributor

@karwosts karwosts commented May 12, 2024

Proposed change

  • Show energy sources table when only gas or water is defined.
  • When all grid sources are deleted, treat this as if we have no grid source (otherwise empty cards and empty row in sources table is shown if grid is added and then deleted).

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

@silamon
Copy link
Contributor

silamon commented May 12, 2024

Proposed change

  • When all grid sources are deleted, treat this as if we have no grid source (otherwise empty cards and empty row in sources table is shown if grid is added and then deleted).

Somehow, it send this from frontend to backend after I decided to delete all the grid sensors:

    "energy_sources": [
      {
        "type": "gas",
        "stat_energy_from": "sensor.total_gas_ft3",
        "stat_cost": null,
        "entity_energy_price": null,
        "number_energy_price": null
      },
      {
        "type": "grid",
        "flow_from": [],
        "flow_to": [],
        "cost_adjustment_day": 0.0
      }
    ],
    "device_consumption": []

Is there a reason why you did choose to extend the "hasGrid" instead of removing the type from the config? I would expect it to look like this when there's no longer a grid source:

    "energy_sources": [
      {
        "type": "gas",
        "stat_energy_from": "sensor.total_gas_ft3",
        "stat_cost": null,
        "entity_energy_price": null,
        "number_energy_price": null
      }
    ],
    "device_consumption": []

@karwosts
Copy link
Contributor Author

I didn't really think that much about it.

I guess there are installations out now which have this empty grid source saved in their configuration, so I think it makes sense to handle it correctly. If we delete the grid source when deleting the last statistic from to/from, that would fix this for future installations, but it would not fix it for users already in this situation.

But I don't feel too strongly about it one way or another.

@piitaya
Copy link
Member

piitaya commented May 13, 2024

I think we can do both : clean config if no more sources and handle the case with 2 empty arrays in the front-end.

@silamon silamon merged commit 3ebe602 into home-assistant:dev May 13, 2024
14 checks passed
@karwosts karwosts deleted the energy-sources-no-grid branch May 13, 2024 16:43
@silamon
Copy link
Contributor

silamon commented May 13, 2024

I'll take a look to remove the grid type in a separate pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Energy dashboard: if you only setup a gas source, the dashboard does not show section 'Sources'
3 participants