This commit is contained in:
e2002
2023-02-21 18:40:11 +03:00
parent f390872d6a
commit fb26dbbf14
5 changed files with 34 additions and 5 deletions

View File

@@ -39,7 +39,8 @@ from homeassistant.const import (
CONF_NAME, CONF_NAME,
STATE_IDLE, STATE_IDLE,
STATE_PLAYING, STATE_PLAYING,
STATE_OFF STATE_OFF,
STATE_ON,
) )
SUPPORT_YORADIO = SUPPORT_PAUSE | SUPPORT_PLAY | SUPPORT_STOP |\ SUPPORT_YORADIO = SUPPORT_PAUSE | SUPPORT_PLAY | SUPPORT_STOP |\
@@ -264,4 +265,12 @@ class yoradioDevice(MediaPlayerEntity):
async def async_media_pause(self): async def async_media_pause(self):
await self.api.set_command("stop") await self.api.set_command("stop")
self._state = STATE_IDLE self._state = STATE_IDLE
async def async_turn_off(self):
await self.api.set_command("turnoff")
self._state = STATE_OFF
async def async_turn_on(self, **kwargs):
await self.api.set_command("turnon")
self._state = STATE_ON

View File

@@ -39,7 +39,7 @@ void mqttPublishStatus() {
memset(topic, 0, 140); memset(topic, 0, 140);
memset(status, 0, BUFLEN*3); memset(status, 0, BUFLEN*3);
sprintf(topic, "%s%s", MQTT_ROOT_TOPIC, "status"); sprintf(topic, "%s%s", MQTT_ROOT_TOPIC, "status");
sprintf(status, "{\"status\": %d, \"station\": %d, \"name\": \"%s\", \"title\": \"%s\"}", player.mode==PLAYING?1:0, config.store.lastStation, config.station.name, config.station.title); sprintf(status, "{\"status\": %d, \"station\": %d, \"name\": \"%s\", \"title\": \"%s\", \"on\": %d}", player.mode==PLAYING?1:0, config.store.lastStation, config.station.name, config.station.title, config.store.dspon);
mqttClient.publish(topic, 0, true, status); mqttClient.publish(topic, 0, true, status);
} }
} }
@@ -107,6 +107,19 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
player.stepVol(true); player.stepVol(true);
return; return;
} }
if (strcmp(buf, "turnoff") == 0) {
uint8_t sst = config.store.smartstart;
player.stop();
config.store.smartstart = sst;
config.save();
config.setDspOn(0);
return;
}
if (strcmp(buf, "turnon") == 0) {
config.setDspOn(1);
if (config.store.smartstart == 1) player.play(config.store.lastStation);
return;
}
int volume; int volume;
if ( sscanf(buf, "vol %d", &volume) == 1) { if ( sscanf(buf, "vol %d", &volume) == 1) {
if (volume < 0) volume = 0; if (volume < 0) volume = 0;

View File

@@ -146,6 +146,8 @@ void Player::setOutputPins(bool isPlaying) {
} }
void Player::play(uint16_t stationId, uint32_t filePos) { void Player::play(uint16_t stationId, uint32_t filePos) {
remoteStationName = false;
config.setDspOn(1);
display.putRequest(PSTOP); display.putRequest(PSTOP);
setDefaults(); setDefaults();
setOutputPins(false); setOutputPins(false);
@@ -175,6 +177,8 @@ void Player::play(uint16_t stationId, uint32_t filePos) {
#ifdef MQTT_ROOT_TOPIC #ifdef MQTT_ROOT_TOPIC
void Player::browseUrl(){ void Player::browseUrl(){
remoteStationName = true;
config.setDspOn(1);
resumeAfterUrl = mode==PLAYING; resumeAfterUrl = mode==PLAYING;
display.putRequest(PSTOP); display.putRequest(PSTOP);
setDefaults(); setDefaults();

View File

@@ -41,6 +41,7 @@ class Player: public Audio {
#ifdef MQTT_ROOT_TOPIC #ifdef MQTT_ROOT_TOPIC
void browseUrl(); void browseUrl();
#endif #endif
bool remoteStationName = false;
void stop(const char *nttl = NULL); void stop(const char *nttl = NULL);
void prev(); void prev();
void next(); void next();

View File

@@ -142,9 +142,11 @@ void audio_showstation(const char *info) {
bool p = printable(info); bool p = printable(info);
config.setTitle(p?info:config.station.name); config.setTitle(p?info:config.station.name);
netserver.requestOnChange(TITLE, 0); netserver.requestOnChange(TITLE, 0);
config.setStation(p?info:config.station.name); if(player.remoteStationName){
display.putRequest(NEWSTATION); config.setStation(p?info:config.station.name);
netserver.requestOnChange(STATION, 0); display.putRequest(NEWSTATION);
netserver.requestOnChange(STATION, 0);
}
} }
} }