mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 16:38:16 +01:00
Added vol +/- control to dfplayer (#1856)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
3b18f1b87f
commit
2b9350ce76
3 changed files with 42 additions and 0 deletions
|
@ -43,6 +43,8 @@ PreviousAction = dfplayer_ns.class_("PreviousAction", automation.Action)
|
||||||
PlayFileAction = dfplayer_ns.class_("PlayFileAction", automation.Action)
|
PlayFileAction = dfplayer_ns.class_("PlayFileAction", automation.Action)
|
||||||
PlayFolderAction = dfplayer_ns.class_("PlayFolderAction", automation.Action)
|
PlayFolderAction = dfplayer_ns.class_("PlayFolderAction", automation.Action)
|
||||||
SetVolumeAction = dfplayer_ns.class_("SetVolumeAction", automation.Action)
|
SetVolumeAction = dfplayer_ns.class_("SetVolumeAction", automation.Action)
|
||||||
|
VolumeUpAction = dfplayer_ns.class_("VolumeUpAction", automation.Action)
|
||||||
|
VolumeDownAction = dfplayer_ns.class_("VolumeDownAction", automation.Action)
|
||||||
SetEqAction = dfplayer_ns.class_("SetEqAction", automation.Action)
|
SetEqAction = dfplayer_ns.class_("SetEqAction", automation.Action)
|
||||||
SleepAction = dfplayer_ns.class_("SleepAction", automation.Action)
|
SleepAction = dfplayer_ns.class_("SleepAction", automation.Action)
|
||||||
ResetAction = dfplayer_ns.class_("ResetAction", automation.Action)
|
ResetAction = dfplayer_ns.class_("ResetAction", automation.Action)
|
||||||
|
@ -201,6 +203,36 @@ async def dfplayer_set_volume_to_code(config, action_id, template_arg, args):
|
||||||
return var
|
return var
|
||||||
|
|
||||||
|
|
||||||
|
@automation.register_action(
|
||||||
|
"dfplayer.volume_up",
|
||||||
|
VolumeUpAction,
|
||||||
|
cv.Schema(
|
||||||
|
{
|
||||||
|
cv.GenerateID(): cv.use_id(DFPlayer),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
async def dfplayer_volume_up_to_code(config, action_id, template_arg, args):
|
||||||
|
var = cg.new_Pvariable(action_id, template_arg)
|
||||||
|
await cg.register_parented(var, config[CONF_ID])
|
||||||
|
return var
|
||||||
|
|
||||||
|
|
||||||
|
@automation.register_action(
|
||||||
|
"dfplayer.volume_down",
|
||||||
|
VolumeDownAction,
|
||||||
|
cv.Schema(
|
||||||
|
{
|
||||||
|
cv.GenerateID(): cv.use_id(DFPlayer),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
async def dfplayer_volume_down_to_code(config, action_id, template_arg, args):
|
||||||
|
var = cg.new_Pvariable(action_id, template_arg)
|
||||||
|
await cg.register_parented(var, config[CONF_ID])
|
||||||
|
return var
|
||||||
|
|
||||||
|
|
||||||
@automation.register_action(
|
@automation.register_action(
|
||||||
"dfplayer.set_eq",
|
"dfplayer.set_eq",
|
||||||
SetEqAction,
|
SetEqAction,
|
||||||
|
|
|
@ -180,6 +180,8 @@ DFPLAYER_SIMPLE_ACTION(StartAction, start)
|
||||||
DFPLAYER_SIMPLE_ACTION(PauseAction, pause)
|
DFPLAYER_SIMPLE_ACTION(PauseAction, pause)
|
||||||
DFPLAYER_SIMPLE_ACTION(StopAction, stop)
|
DFPLAYER_SIMPLE_ACTION(StopAction, stop)
|
||||||
DFPLAYER_SIMPLE_ACTION(RandomAction, random)
|
DFPLAYER_SIMPLE_ACTION(RandomAction, random)
|
||||||
|
DFPLAYER_SIMPLE_ACTION(VolumeUpAction, volume_up)
|
||||||
|
DFPLAYER_SIMPLE_ACTION(VolumeDownAction, volume_down)
|
||||||
|
|
||||||
template<typename... Ts> class DFPlayerIsPlayingCondition : public Condition<Ts...>, public Parented<DFPlayer> {
|
template<typename... Ts> class DFPlayerIsPlayingCondition : public Condition<Ts...>, public Parented<DFPlayer> {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -141,6 +141,14 @@ api:
|
||||||
then:
|
then:
|
||||||
- dfplayer.random
|
- dfplayer.random
|
||||||
|
|
||||||
|
- service: dfplayer_volume_up
|
||||||
|
then:
|
||||||
|
- dfplayer.volume_up
|
||||||
|
|
||||||
|
- service: dfplayer_volume_down
|
||||||
|
then:
|
||||||
|
- dfplayer.volume_down
|
||||||
|
|
||||||
- service: battery_level_percent
|
- service: battery_level_percent
|
||||||
variables:
|
variables:
|
||||||
level_percent: int
|
level_percent: int
|
||||||
|
|
Loading…
Reference in a new issue