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

[yamahamusiccast] Initial contribution #11880

Merged
merged 9 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@
/bundles/org.openhab.binding.wolfsmartset/ @BoBiene
/bundles/org.openhab.binding.xmltv/ @clinique
/bundles/org.openhab.binding.xmppclient/ @pavel-gololobov
/bundles/org.openhab.binding.yamahareceiver/ @davidgraeff @zarusz
/bundles/org.openhab.binding.yamahamusiccast/ @coop-git
/bundles/org.openhab.binding.yamahareceiver/ @davidgraeff @zarusz
/bundles/org.openhab.binding.yeelight/ @claell
/bundles/org.openhab.binding.yioremote/ @miloit
/bundles/org.openhab.binding.zoneminder/ @mhilbush
Expand Down
4 changes: 2 additions & 2 deletions bom/openhab-addons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1698,12 +1698,12 @@
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.yamahareceiver</artifactId>
<artifactId>org.openhab.binding.yamahamusiccast</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.yamahamusiccast</artifactId>
<artifactId>org.openhab.binding.yamahareceiver</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class YamahaMusiccastBridgeHandler extends BaseBridgeHandler {
private Gson gson = new Gson();
private final Logger logger = LoggerFactory.getLogger(YamahaMusiccastBridgeHandler.class);
private String threadname = getThing().getUID().getAsString();
private @Nullable ExecutorService executor = Executors.newSingleThreadExecutor(new NamedThreadFactory(threadname));
private @Nullable ExecutorService executor;
private @Nullable Future<?> eventListenerJob;
private static final int UDP_PORT = 41100;
private static final int SOCKET_TIMEOUT_MILLISECONDS = 3000;
Expand All @@ -64,9 +64,9 @@ private void receivePackets() {
InetSocketAddress address = new InetSocketAddress(UDP_PORT);
s.bind(address);
socket = s;
logger.debug("UDP Listener got socket on port {} with timeout {}", UDP_PORT, SOCKET_TIMEOUT_MILLISECONDS);
logger.trace("UDP Listener got socket on port {} with timeout {}", UDP_PORT, SOCKET_TIMEOUT_MILLISECONDS);
} catch (SocketException e) {
logger.debug("UDP Listener got SocketException: {}", e.getMessage(), e);
logger.trace("UDP Listener got SocketException: {}", e.getMessage(), e);
socket = null;
return;
}
Expand All @@ -78,16 +78,16 @@ private void receivePackets() {
localSocket.receive(packet);
String received = new String(packet.getData(), 0, packet.getLength());
String trackingID = UUID.randomUUID().toString().replace("-", "").substring(0, 32);
logger.debug("Received packet: {} (Tracking: {})", received, trackingID);
logger.trace("Received packet: {} (Tracking: {})", received, trackingID);
handleUDPEvent(received, trackingID);
} catch (SocketTimeoutException e) {
// Nothing to do on socket timeout
} catch (IOException e) {
logger.debug("UDP Listener got IOException waiting for datagram: {}", e.getMessage());
logger.trace("UDP Listener got IOException waiting for datagram: {}", e.getMessage());
localSocket = null;
}
}
logger.debug("UDP Listener exiting");
logger.trace("UDP Listener exiting");
}

public YamahaMusiccastBridgeHandler(Bridge bridge) {
Expand All @@ -101,6 +101,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
@Override
public void initialize() {
updateStatus(ThingStatus.ONLINE);
executor = Executors.newSingleThreadExecutor(new NamedThreadFactory(threadname));
Future<?> localEventListenerJob = eventListenerJob;
ExecutorService localExecutor = executor;
if (localEventListenerJob == null || localEventListenerJob.isCancelled()) {
Expand Down Expand Up @@ -132,10 +133,10 @@ public void handleUDPEvent(String json, String trackingID) {
ThingStatusInfo statusInfo = thing.getStatusInfo();
switch (statusInfo.getStatus()) {
case ONLINE:
logger.debug("Thing Status: ONLINE - {}", thing.getLabel());
logger.trace("Thing Status: ONLINE - {}", thing.getLabel());
YamahaMusiccastHandler handler = (YamahaMusiccastHandler) thing.getHandler();
if (handler != null) {
logger.debug("UDP: {} - {} ({} - Tracking: {})", json, handler.getDeviceId(), thing.getLabel(),
logger.trace("UDP: {} - {} ({} - Tracking: {})", json, handler.getDeviceId(), thing.getLabel(),
trackingID);

@Nullable
Expand All @@ -149,7 +150,7 @@ public void handleUDPEvent(String json, String trackingID) {
}
break;
default:
logger.debug("Thing Status: NOT ONLINE - {} (Tracking: {})", thing.getLabel(), trackingID);
logger.trace("Thing Status: NOT ONLINE - {} (Tracking: {})", thing.getLabel(), trackingID);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
String localDefaultAfterMCLink = "";
String localRoleSelectedThing = "";
if (command != RefreshType.REFRESH) {
logger.debug("Handling command {} for channel {}", command, channelUID);
logger.trace("Handling command {} for channel {}", command, channelUID);
channelWithoutGroup = channelUID.getIdWithoutGroup();
zone = channelUID.getGroupId();
DistributionInfo distributioninfo = new DistributionInfo();
Expand All @@ -141,12 +141,12 @@ public void handleCommand(ChannelUID channelUID, Command command) {
// check on scheduler task for UDP events
ScheduledFuture<?> localGeneralHousekeepingTask = generalHousekeepingTask;
if (localGeneralHousekeepingTask == null) {
logger.info("YXC - No scheduler task found!");
logger.trace("YXC - No scheduler task found!");
generalHousekeepingTask = scheduler.scheduleWithFixedDelay(this::generalHousekeeping, 5,
300, TimeUnit.SECONDS);

} else {
logger.info("Scheduler task found!");
logger.trace("Scheduler task found!");
}

} else if (command == OnOffType.OFF) {
Expand Down Expand Up @@ -336,7 +336,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
if ("none".equals(localRole)) {
json = "{\"group_id\":\"" + groupId + "\", \"zone\":\"" + mclinkSetupZone
+ "\", \"type\":\"add\", \"client_list\":[\"" + this.host + "\"]}";
logger.debug("setServerInfo json: {}", json);
logger.trace("setServerInfo json: {}", json);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't dump json data into the logs in the future. You could use the debugger during development or add these dumps to dedicated JARs for certain users if they encounter some problems.

httpResponse = setClientServerInfo(mclinkSetupServer, json, "setServerInfo");
// All zones of Model are required for MC Link
tmpString = "";
Expand All @@ -357,7 +357,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}
}
json = "{\"group_id\":\"" + groupId + "\", \"zone\":[" + tmpString + "]}";
logger.debug("setClientInfo json: {}", json);
logger.trace("setClientInfo json: {}", json);
httpResponse = setClientServerInfo(this.host, json, "setClientInfo");
httpResponse = startDistribution(mclinkSetupServer);
}
Expand Down Expand Up @@ -388,7 +388,7 @@ public void initialize() {
this.host = localHost;
if (!"".equals(this.host)) {
zoneNum = getNumberOfZones(this.host);
logger.debug("Zones found: {} - {}", zoneNum, thingLabel);
logger.trace("Zones found: {} - {}", zoneNum, thingLabel);

if (zoneNum > 0) {
refreshOnStartup();
Expand All @@ -403,7 +403,7 @@ public void initialize() {

private void generalHousekeeping() {
thingLabel = thing.getLabel();
logger.debug("YXC - Start Keep Alive UDP events (5 minutes - {}) ", thingLabel);
logger.trace("YXC - Start Keep Alive UDP events (5 minutes - {}) ", thingLabel);
keepUdpEventsAlive(this.host);
fillOptionsForMCLink();
updateMCLinkStatus();
Expand Down Expand Up @@ -481,7 +481,7 @@ private void powerOffCleanup() {
}

public void processUDPEvent(String json, String trackingID) {
logger.debug("UDP package: {} (Tracking: {})", json, trackingID);
logger.trace("UDP package: {} (Tracking: {})", json, trackingID);
@Nullable
UdpMessage targetObject = gson.fromJson(json, UdpMessage.class);
if (targetObject != null) {
Expand Down Expand Up @@ -517,7 +517,7 @@ private void updateStateFromUDPEvent(String zoneToUpdate, UdpMessage targetObjec
int presetNumber = 0;
int playTime = 0;
String distInfoUpdated = "";
logger.debug("Handling UDP for {}", zoneToUpdate);
logger.trace("Handling UDP for {}", zoneToUpdate);
switch (zoneToUpdate) {
case "main":
powerState = targetObject.getMain().getPower();
Expand Down Expand Up @@ -594,7 +594,7 @@ private void updateStateFromUDPEvent(String zoneToUpdate, UdpMessage targetObjec
}

if (presetNumber != 0) {
logger.debug("Preset detected: {}", presetNumber);
logger.trace("Preset detected: {}", presetNumber);
updatePresets(presetNumber);
}

Expand Down Expand Up @@ -629,14 +629,14 @@ private void updateStatusZone(String zoneToUpdate) {
soundProgramState = targetObject.getSoundProgram();
sleepState = targetObject.getSleep();

logger.debug("{} - Response: {}", zoneToUpdate, responseCode);
logger.debug("{} - Power: {}", zoneToUpdate, powerState);
logger.debug("{} - Mute: {}", zoneToUpdate, muteState);
logger.debug("{} - Volume: {}", zoneToUpdate, volumeState);
logger.debug("{} - Max Volume: {}", zoneToUpdate, maxVolumeState);
logger.debug("{} - Input: {}", zoneToUpdate, inputState);
logger.debug("{} - Soundprogram: {}", zoneToUpdate, soundProgramState);
logger.debug("{} - Sleep: {}", zoneToUpdate, sleepState);
logger.trace("{} - Response: {}", zoneToUpdate, responseCode);
logger.trace("{} - Power: {}", zoneToUpdate, powerState);
logger.trace("{} - Mute: {}", zoneToUpdate, muteState);
logger.trace("{} - Volume: {}", zoneToUpdate, volumeState);
logger.trace("{} - Max Volume: {}", zoneToUpdate, maxVolumeState);
logger.trace("{} - Input: {}", zoneToUpdate, inputState);
logger.trace("{} - Soundprogram: {}", zoneToUpdate, soundProgramState);
logger.trace("{} - Sleep: {}", zoneToUpdate, sleepState);

switch (responseCode) {
case "0":
Expand Down Expand Up @@ -701,7 +701,7 @@ private void updateStatusZone(String zoneToUpdate) {
}
break;
case "999":
logger.debug("Nothing to do! - {} ({})", thingLabel, zoneToUpdate);
logger.trace("Nothing to do! - {} ({})", thingLabel, zoneToUpdate);
break;
}
}
Expand Down Expand Up @@ -879,7 +879,7 @@ private void fillOptionsForMCLink() {
for (Thing thing : bridge.getThings()) {
label = thing.getLabel();
host = thing.getConfiguration().get("host").toString();
logger.debug("Thing found on Bridge: {} - {}", label, host);
logger.trace("Thing found on Bridge: {} - {}", label, host);
zonesPerHost = getNumberOfZones(host);
for (int i = 1; i <= zonesPerHost; i++) {
switch (i) {
Expand Down Expand Up @@ -962,7 +962,7 @@ private int getNumberOfZones(@Nullable String host) {
}

private void setVolumeLinkedDevice(int value, @Nullable String zone, String host) {
logger.debug("setVolumeLinkedDevice: {}", host);
logger.trace("setVolumeLinkedDevice: {}", host);
int zoneNumLinkedDevice = getNumberOfZones(host);
int maxVolumeLinkedDevice = 0;
@Nullable
Expand Down Expand Up @@ -1111,10 +1111,10 @@ private String makeRequest(@Nullable String topicAVR, String url) {
String response = "";
try {
response = HttpUtil.executeUrl("GET", HTTP + url, LONG_CONNECTION_TIMEOUT_MILLISEC);
logger.debug("{} - {}", topicAVR, response);
logger.trace("{} - {}", topicAVR, response);
return response;
} catch (IOException e) {
logger.warn("IO Exception - {} - {}", topicAVR, e.getMessage());
logger.trace("IO Exception - {} - {}", topicAVR, e.getMessage());
return "{\"response_code\":\"999\"}";
}
}
Expand Down Expand Up @@ -1201,10 +1201,10 @@ private String makeRequest(@Nullable String topicAVR, String url) {
try {
url = "http://" + host + YAMAHA_EXTENDED_CONTROL + "dist/" + type;
httpResponse = HttpUtil.executeUrl("POST", url, is, "", LONG_CONNECTION_TIMEOUT_MILLISEC);
logger.debug("MC Link/Unlink Client {}", httpResponse);
logger.trace("MC Link/Unlink Client {}", httpResponse);
return httpResponse;
} catch (IOException e) {
logger.warn("IO Exception - {} - {}", type, e.getMessage());
logger.trace("IO Exception - {} - {}", type, e.getMessage());
return "{\"response_code\":\"999\"}";
}
}
Expand Down Expand Up @@ -1234,10 +1234,10 @@ private void keepUdpEventsAlive(@Nullable String host) {
try {
httpResponse = HttpUtil.executeUrl("GET", HTTP + host + YAMAHA_EXTENDED_CONTROL + "netusb/getPlayInfo",
appProps, null, "", LONG_CONNECTION_TIMEOUT_MILLISEC);
// logger.debug("{}", httpResponse);
logger.debug("{} - {}", "UDP task", httpResponse);
// logger.trace("{}", httpResponse);
logger.trace("{} - {}", "UDP task", httpResponse);
} catch (IOException e) {
logger.warn("UDP refresh failed - {}", e.getMessage());
logger.trace("UDP refresh failed - {}", e.getMessage());
}
}
// End General/System API calls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</channel-group-type>

<channel-group-type id="playerControls">
<label>player Controls</label>
<label>Player Controls</label>
<channels>
<channel id="player" typeId="player"/>
<channel id="artist" typeId="artist"/>
Expand Down
2 changes: 1 addition & 1 deletion bundles/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@
<module>org.openhab.binding.wolfsmartset</module>
<module>org.openhab.binding.xmltv</module>
<module>org.openhab.binding.xmppclient</module>
<module>org.openhab.binding.yamahareceiver</module>
<module>org.openhab.binding.yamahamusiccast</module>
<module>org.openhab.binding.yamahareceiver</module>
<module>org.openhab.binding.yioremote</module>
<module>org.openhab.binding.yeelight</module>
<module>org.openhab.binding.zoneminder</module>
Expand Down