Fix hour calculation for midnight in datadis.py#24
Conversation
Adjust hour calculation for midnight cases and update date accordingly.
|
No puedo aceptar esto ya que fallaría en el resto de distribuidoras, que siguen usando el mismo formato de fecha que siempre. A priori, parece un error eventual de la distribuidora IDE, y no un cambio de criterio en su API. Sin ir más lejos, a algunos usuarios, IDE le ha empezado a dar los datos en el formato de fecha adecuado (uvejota/homeassistant-edata#310 (comment)) |
The original code crashes on "time": "0:00" regardless of distributor:
My fix only adds special handling for hour 0, preserving existing logic for hours 1-23. This is a boundary condition fix, not an i-DE-specific workaround. |
En primer lugar, muchas gracias por colaborar. Te explico la "problemática". El resto de distribuidoras nunca envían un 0, sino que devuelven de 1 a 24 horas. Donde 1 representa el consumo de 00h a 01h (indicando el final del periodo, criterio A). El código no está preparado para recibir un 0, porque nunca debe recibirlo ya que eso podría implicar un cambio de criterio. Por ejemplo, supones que cuando i-DE te devuelve 0h se refiere al consumo desde las 23h del día anterior hasta las 00h, lo cual no tiene por qué ser cierto. Puede significar que "0" representa el consumo desde las 00h a las 01h (indicando el inicio del periodo, criterio B). Entiendo que tu fix no perjudica a otras distribuidoras, pero a los usuarios de i-DE podría asignarle consumos a horas erróneas si ha cambiado el criterio (de A a B). Antes de hacer este cambio hay que asegurarse de ello. Hay otro "pero", y es que i-DE ha intercambiado el mes y día en la cadena de texto que representa la hora/fecha del consumo, siendo en lugar de YYYY-mm-dd, YYYY-dd-mm. Esto le ha pasado a este usuario: uvejota/homeassistant-edata#310 (comment). Esto es lo que más me frena a hacer este tipo de cambios. ¡Es mejor que "falle" a que asigne consumos a otro mes! Además, ese mismo usuario (y otros) avisan unos mensajes más tarde de que se le ha solucionado solo. Puede ser porque i-DE ha arreglado el formato. ¿A algunos, o a todos los usuarios? Quién sabe. Si no se soluciona en unos días, buscaremos una solución investigando bien el alcance del problema, pero mientras tanto no me atrevo. First of all, thank you very much for collaborating. Let me explain the "issue" at hand. Other distributors never send a "0"; instead, they return values from 1 to 24. In their case, 1 represents the consumption from 00:00 to 01:00 (indicating the end of the period, Criterion A). The code isn't prepared to receive a 0 because it should never receive one—doing so could imply a shift in criteria. For example, you are assuming that when i-DE returns "0h," it refers to the consumption from 23:00 the previous day until 00:00, but that isn't necessarily true. It could mean that "0" represents the consumption from 00:00 to 01:00 (indicating the start of the period, Criterion B). I understand that your fix doesn't negatively affect other distributors, but for i-DE users, it could assign consumption to the wrong hours if the criteria has changed (from A to B). We need to confirm this before making the change. There is another "but": i-DE has swapped the month and day in the string representing the date/time of consumption, using YYYY-dd-mm instead of YYYY-mm-dd. This happened to this user: uvejota/homeassistant-edata#310 (comment). This is the main thing holding me back from making these types of changes. It’s better for it to "fail" than to assign consumption to the wrong month! Furthermore, that same user (and others) mentioned a few messages later that the problem resolved itself. It’s possible i-DE fixed the format. For some users, or all of them? Who knows. If it isn't resolved in a few days, we will look for a solution by thoroughly investigating the scope of the problem, but in the meantime, I don't feel comfortable proceeding. |
|
Thank you for sharing your concerns. I completely understand them - you know the code best and you know what such a change might affect. Let's wait and see if anything improves on the Datadis side. |
Adjust hour calculation for midnight cases and update date accordingly.
The Datadis API has changed the hour format from 01:00-24:00 to 00:00-23:00 (at least for distributor 8 = IDE).
This is related to uvejota/homeassistant-edata#310