|
| 1 | +package io.github.hapjava.services.impl; |
| 2 | + |
| 3 | +import io.github.hapjava.accessories.SmartSpeakerAccessory; |
| 4 | +import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithAirPlayEnable; |
| 5 | +import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithConfiguredName; |
| 6 | +import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithMute; |
| 7 | +import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; |
| 8 | +import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithVolume; |
| 9 | +import io.github.hapjava.characteristics.impl.audio.MuteCharacteristic; |
| 10 | +import io.github.hapjava.characteristics.impl.audio.VolumeCharacteristic; |
| 11 | +import io.github.hapjava.characteristics.impl.common.AirPlayEnableCharacteristic; |
| 12 | +import io.github.hapjava.characteristics.impl.common.ConfiguredNameCharacteristic; |
| 13 | +import io.github.hapjava.characteristics.impl.common.NameCharacteristic; |
| 14 | +import io.github.hapjava.characteristics.impl.television.CurrentMediaStateCharacteristic; |
| 15 | +import io.github.hapjava.characteristics.impl.television.TargetMediaStateCharacteristic; |
| 16 | + |
| 17 | +/** A smart speaker service can be used to control the audio output settings on a speaker device. */ |
| 18 | +public class SmartSpeakerService extends AbstractServiceImpl { |
| 19 | + |
| 20 | + public SmartSpeakerService( |
| 21 | + CurrentMediaStateCharacteristic currentMediaStateCharacteristic, |
| 22 | + TargetMediaStateCharacteristic targetMediaStateCharacteristic) { |
| 23 | + super("00000228-0000-1000-8000-0026BB765291"); |
| 24 | + addCharacteristic(currentMediaStateCharacteristic); |
| 25 | + addCharacteristic(targetMediaStateCharacteristic); |
| 26 | + } |
| 27 | + |
| 28 | + public SmartSpeakerService(SmartSpeakerAccessory accessory) { |
| 29 | + this( |
| 30 | + new CurrentMediaStateCharacteristic( |
| 31 | + accessory::getCurrentMediaState, |
| 32 | + accessory::subscribeCurrentMediaState, |
| 33 | + accessory::unsubscribeCurrentMediaState), |
| 34 | + new TargetMediaStateCharacteristic( |
| 35 | + accessory::getTargetMediaState, |
| 36 | + accessory::setTargetMediaState, |
| 37 | + accessory::subscribeTargetMediaState, |
| 38 | + accessory::unsubscribeTargetMediaState)); |
| 39 | + if (accessory instanceof AccessoryWithName) { |
| 40 | + addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); |
| 41 | + } |
| 42 | + if (accessory instanceof AccessoryWithVolume) { |
| 43 | + addOptionalCharacteristic( |
| 44 | + new VolumeCharacteristic( |
| 45 | + ((AccessoryWithVolume) accessory)::getVolume, |
| 46 | + ((AccessoryWithVolume) accessory)::setVolume, |
| 47 | + ((AccessoryWithVolume) accessory)::subscribeVolume, |
| 48 | + ((AccessoryWithVolume) accessory)::unsubscribeVolume)); |
| 49 | + } |
| 50 | + if (accessory instanceof AccessoryWithConfiguredName) { |
| 51 | + addOptionalCharacteristic( |
| 52 | + new ConfiguredNameCharacteristic( |
| 53 | + ((AccessoryWithConfiguredName) accessory)::getConfiguredName, |
| 54 | + ((AccessoryWithConfiguredName) accessory)::setConfiguredName, |
| 55 | + ((AccessoryWithConfiguredName) accessory)::subscribeConfiguredName, |
| 56 | + ((AccessoryWithConfiguredName) accessory)::unsubscribeConfiguredName)); |
| 57 | + } |
| 58 | + if (accessory instanceof AccessoryWithMute) { |
| 59 | + addOptionalCharacteristic( |
| 60 | + new MuteCharacteristic( |
| 61 | + ((AccessoryWithMute) accessory)::isMuted, |
| 62 | + ((AccessoryWithMute) accessory)::setMute, |
| 63 | + ((AccessoryWithMute) accessory)::subscribeMuteState, |
| 64 | + ((AccessoryWithMute) accessory)::unsubscribeMuteState)); |
| 65 | + } |
| 66 | + if (accessory instanceof AccessoryWithAirPlayEnable) { |
| 67 | + addOptionalCharacteristic( |
| 68 | + new AirPlayEnableCharacteristic( |
| 69 | + ((AccessoryWithAirPlayEnable) accessory)::getAirPlayEnable, |
| 70 | + ((AccessoryWithAirPlayEnable) accessory)::setAirPlayEnable, |
| 71 | + ((AccessoryWithAirPlayEnable) accessory)::subscribeAirPlayEnable, |
| 72 | + ((AccessoryWithAirPlayEnable) accessory)::unsubscribeAirPlayEnable)); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + public void addOptionalCharacteristic(NameCharacteristic name) { |
| 77 | + addCharacteristic(name); |
| 78 | + } |
| 79 | + |
| 80 | + public void addOptionalCharacteristic(VolumeCharacteristic volume) { |
| 81 | + addCharacteristic(volume); |
| 82 | + } |
| 83 | + |
| 84 | + public void addOptionalCharacteristic(ConfiguredNameCharacteristic configuredNameCharacteristic) { |
| 85 | + addCharacteristic(configuredNameCharacteristic); |
| 86 | + } |
| 87 | + |
| 88 | + public void addOptionalCharacteristic(MuteCharacteristic muteCharacteristic) { |
| 89 | + addCharacteristic(muteCharacteristic); |
| 90 | + } |
| 91 | + |
| 92 | + public void addOptionalCharacteristic(AirPlayEnableCharacteristic airPlayEnableCharacteristic) { |
| 93 | + addCharacteristic(airPlayEnableCharacteristic); |
| 94 | + } |
| 95 | +} |
0 commit comments