Fix time duration when HA isn't updating position
This commit is contained in:
@@ -728,8 +728,9 @@ api:
|
||||
volume_level: int
|
||||
media_title: string
|
||||
media_artist: string
|
||||
media_duration: int
|
||||
media_position: int
|
||||
media_duration: float
|
||||
media_position: float
|
||||
media_position_delta: float
|
||||
supported_features: int
|
||||
then:
|
||||
- lambda: |-
|
||||
@@ -845,7 +846,12 @@ api:
|
||||
|
||||
if (media_duration > 0)
|
||||
{
|
||||
id(disp1).set_component_value("prg_current", media_position);
|
||||
if (media_duration != id(last_media_duration) or media_position != id(last_media_position))
|
||||
{
|
||||
id(last_media_duration) = media_duration;
|
||||
id(last_media_position) = media_position;
|
||||
id(disp1).set_component_value("prg_current", int(round(min(media_position + media_position_delta, media_duration))));
|
||||
}
|
||||
id(disp1).set_component_value("prg_total", media_duration);
|
||||
id(disp1).send_command_printf("prg_timer.en=%i", (state == "playing") ? 1 : 0);
|
||||
id(disp1).show_component("time_current");
|
||||
@@ -870,6 +876,18 @@ globals:
|
||||
restore_value: false
|
||||
initial_value: '-1'
|
||||
|
||||
###### Last duration from Home Assistant ######
|
||||
- id: last_media_duration
|
||||
type: int
|
||||
restore_value: false
|
||||
initial_value: '-1'
|
||||
|
||||
###### Last duration from Home Assistant ######
|
||||
- id: last_media_position
|
||||
type: int
|
||||
restore_value: false
|
||||
initial_value: '-1'
|
||||
|
||||
###### Relay fallback even when buttons have other entities? ######
|
||||
- id: relay_1_fallback
|
||||
type: bool
|
||||
@@ -1256,7 +1274,12 @@ text_sensor:
|
||||
then:
|
||||
- lambda: |-
|
||||
if (x != "climate" and x != "cover" and x != "fan" and x != "light" and x != "media_player" and x != "confirm" and x != "keyb_num") id(entity_id) = "";
|
||||
if (x != "media_player") id(last_volume_level) = -1;
|
||||
if (x != "media_player")
|
||||
{
|
||||
id(last_volume_level) = -1;
|
||||
id(last_media_duration) = -1;
|
||||
id(last_media_position) = -1;
|
||||
}
|
||||
ESP_LOGD("text_sensor.current_page", "New page: %s", x.c_str());
|
||||
if (!id(entity_id).empty()) ESP_LOGD("text_sensor.current_page", "Entity shown: %s", id(entity_id).c_str());
|
||||
id(timer_reset_all).execute(x.c_str());
|
||||
|
||||
Reference in New Issue
Block a user