44
55namespace whatwedo \MonitorBundle \Normalizer ;
66
7+ use Symfony \Component \Serializer \Normalizer \NormalizerAwareInterface ;
8+ use Symfony \Component \Serializer \Normalizer \NormalizerAwareTrait ;
79use Symfony \Component \Serializer \Normalizer \NormalizerInterface ;
810use whatwedo \MonitorBundle \Monitoring \AttributeInterface ;
911use whatwedo \MonitorBundle \Monitoring \Metric \AbstractMetric ;
12+ use whatwedo \MonitorBundle \Monitoring \Metric \MetricStateInterface ;
1013use whatwedo \MonitorBundle \Monitoring \Sensor \AbstractSensor ;
14+ use whatwedo \MonitorBundle \Monitoring \Sensor \SensorStateInterface ;
1115
12- class AttributeNormalizer implements NormalizerInterface
16+ class AttributeNormalizer implements NormalizerInterface, NormalizerAwareInterface
1317{
18+ use NormalizerAwareTrait;
19+
1420 /**
1521 * @param AttributeInterface $object
1622 */
@@ -20,13 +26,18 @@ public function normalize($object, string $format = null, array $context = []):
2026 'name ' => $ object ->getName (),
2127 ];
2228
29+ try {
30+ if ($ object instanceof MetricStateInterface || $ object instanceof SensorStateInterface) {
31+ $ data ['state ' ] = $ this ->normalizer ->normalize ($ object ->getState ());
32+ }
33+ } catch (\LogicException ) {
34+ }
35+
2336 if ($ object instanceof AbstractSensor) {
24- $ data ['state ' ] = $ object ->getState ();
2537 $ data ['details ' ] = $ object ->getDetails ();
2638 }
2739
2840 if ($ object instanceof AbstractMetric) {
29- $ data ['state ' ] = $ object ->getState ();
3041 $ data ['value ' ] = $ object ->getValue ();
3142 }
3243
0 commit comments